updating your xamarin.ios apps to ios9 -...

33
// Updating your Xamarin.iOS apps to iOS9 Mark Smith | [email protected]

Upload: duonghanh

Post on 11-Feb-2018

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

//

Updating your Xamarin.iOS apps to iOS9

Mark Smith | [email protected]

Page 2: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

Information in this document is subject to change without notice. The example companies, organizations, products, people, and events depicted herein are fictitious. No association with any real company, organization, product, person or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user.

Xamarin may have patents, patent applications, trademarked, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any license agreement from Xamarin, the furnishing of this document does not give you any license to these patents, trademarks, or other intellectual property.

© 2015 Xamarin. All rights reserved.

Xamarin, MonoTouch, MonoDroid, Xamarin.iOS, Xamarin.Android, and Xamarin Studio are either registered trademarks or trademarks of Xamarin in the U.S.A. and/or other countries.

Other product and company names herein may be the trademarks of their respective owners.

Page 3: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

1. Explore the update options2. Make your app iOS9 compatible3. Integrate iOS9 features into your app4. Know the breaking changes

Agenda

Page 4: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

Two phases to think about

Ensure your app is compatible with iOS9

Update your app to take advantage of new iOS9 features

Page 5: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

1. Due to iOS changes, you mustrecompile your app

2. Might have to make some minor tweaks based on what you use today

3. Resubmit to the App Store ASAP to make sure users don't encounter problems

Steps to compatibility

Page 6: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Update to the Xamarin stable channel (XS and VS)

v Can use either Xcode 6.4 or Xcode 7.0

v Can keep iOS 8 (or earlier) as your deployment target to continue to run on older devices

Recompiling your app

Page 7: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v iOS9 has a few breaking changes with initializers that apps might run into; should add new exported constructors to be compatible

Improving compatibility with iOS9

Custom UICollectionViewCell classes require parameterized constructor

public class MyCustomCell : UICollectionViewCell{

[Export ("initWithFrame:")]public MyCustomCell (CGRect frame) : base (frame) {

... // Call common init code}...

}

Page 8: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v iOS9 has a few breaking changes with initializers that apps might run into; should add new exported constructors to be compatible

Improving compatibility with iOS9

UIViews loaded from .XIB files now use initWithCoder: constructor

public class AnimatedButton : UIButton{

[Export ("initWithCoder:")]public AnimatedButton (NSCoder coder) : base (coder) {

... // Call common init code}...

}

Page 9: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Xamarin is collecting known issues developers have encountered while moving to iOS9 in a single place - http://bit.ly/ios9-issues

Troubleshooting iOS9 issues

Page 10: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Make sure to test all screens and workflows; several APIs are now more strict with parameter checking§ E.g. Constraints in Auto Layout

v Make sure you test on real devices, Xamarin Test Cloud is great for this – use your free minutes!

Test your app thoroughly!

Page 11: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Xcode only includes latest iOS images – but can download older versions of iOS Simulators from Xcode > Preferences > Downloads

Testing on older versions of iOS

Page 12: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Get your updated and tested app into the queue for the AppStore

v Currently taking about a week to get through the review process

v Can then focus on new features and really taking advantage of iOS9

Resubmit to the AppStore

Page 13: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Update to Xcode 7 to get access to the new iOS9 APIs

Installing Xcode 7

Page 14: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

Several great new features in iOS9

Multitasking on the iPad

3DTouch

SearchEnhancements

Game APIs VariousFramework APIs

Page 15: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Be careful about using new features if your deployment target isn't 9.0

Targeting iOS9 features

Xamarin Studio will try to warn you when your deployment target is

lower than an API being used through tooltips

Page 16: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Using a new API on an older version of iOS results in a runtime exception

Targeting iOS9 features

Page 17: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Should check the runtime version before using new APIs to continue to be backward compatible

Targeting iOS9 features

// Make sure we are on iOS 9.0 or greaterif (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) {

if (TraitCollection.ForceTouchCapability== UIForceTouchCapability.Available)

{...

}}

Page 18: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v When moving fully to iOS9 and Xcode 7, can check for updates to components or Nuget packages your application utilizes; should be a little cautious here to make sure you don't introduce problems

Update components / Nuget

Page 19: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Xamarin iOS Designer does not support the new UI features added to Xcode 7 (yet)

v On XS, can right-click and select Open With > Xcode Interface Builder

v Make changes, save and return to Xamarin Studio to edit code

Storyboard Designer

Check out the walkthrough on using UIStackView in the Xamarin documentation, or watch the Lightning Lecture on using UIStackView in iOS9 for examples of this approach

Page 20: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Recommended to add a Launch File to provide the launch screen on iOS8 and beyond; required to support split-screen on iPad

Launch File vs. Launch Images

Create it with the designer as either a .xib or .storyboard and then assign it in the info.plist

This is becoming more important as more devices are introduced such as the iPad Pro

Page 21: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v The Address Book and Address Book UI frameworks have been replaced with a new, simpler Contacts and Contacts UI API which is the preferred way to interact with the contact information on the device

Replacing deprecated APIs (iOS9 only!)

// Create a new contact pickervar picker = new CNContactPickerViewController {

DisplayedPropertyKeys = new[] {CNContactKey.EmailAddresses},PredicateForEnablingContact = NSPredicate.FromFormat("emailAddresses.@count > 0"),PredicateForSelectionOfContact = NSPredicate.FromFormat("emailAddresses.@count == 1"),Delegate = new ContactPickerDelegate()

};

// Display pickerPresentViewController(picker,true, null);

developer.xamarin.com/guides/ios/platform_features/introduction_to_ios9/contacts/

Page 22: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Apple has made some security and privacy changes to iOS9 which will affect any application linked to the iOS9 SDK

v Even if your application does not use iOS9 APIs, if you link to the latest SDK, these changes will apply to your app!

Security changes in iOS9

Page 23: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v New security policy enforces tighter requirements on network connections§ Requires TLS 1.2 or better (https)§ Must use a modern key exchange

algorithm that provides forward security§ Certificates must be signed with SHA256,

2048-bit RSA key, or better

App Transport Security

Read the Apple technical note for more details: http://apple.co/1JbkkRV

Page 24: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v New security policy enforces tighter requirements on network connections§ Requires TLS 1.2 or better (https)§ Must use a modern key exchange

algorithm that provides forward security§ Certificates must be signed with SHA256,

2048-bit RSA key, or better

App Transport Security

If your application is currently using https and good certificates, then this change will likely not affect you

Page 25: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v ATS secures the native iOS stack:§ NSUrlSession/Connection§ Embedded web views§ Background transfers§ ModernHttpClient (Nuget)

v Test edge areas of your app that perform network access such as ad-revenue, in-app OAuth logins, social media integration, etc.

What APIs does this affect?

Page 26: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v ATS policy violations result in an exception + debug output, most common cause is connection to an http (not https) endpoint, but can also happen when older algorithms are negotiated

v Two possible solutions: update the connection to comply to the policy, or tell ATS to ignore the connection

Detecting ATS problems

Page 27: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Can add exceptions into info.plist if your app cannot comply to restrictions – use new NSAppTransportSecurity key

Adding exceptions for ATS

<key>NSAppTransportSecurity</key><dict>

<key>NSExceptionDomains</key><dict>

<key>xam150.azurewebsites.net</key><dict>

<!-- specific options here --></dict>

</dict></dict>

Try to identify the specific endpoints your app uses and configure just those endpoints

Page 28: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

<key>xam150.azurewebsites.net</key><dict>

<key>NSExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key>NSExceptionRequiresForwardSecrecy</key><false/><key>NSExceptionAllowsInsecureHTTPLoads</key><true/><key>NSIncludesSubdomains</key><true/>

</dict>

Exclusion options

Minimum version of TLS to allow

Page 29: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

<key>xam150.azurewebsites.net</key><dict>

<key>NSExceptionMinimumTLSVersion</key><string>TLSv1.0</string><key>NSExceptionRequiresForwardSecrecy</key><false/><key>NSExceptionAllowsInsecureHTTPLoads</key><true/><key>NSIncludesSubdomains</key><true/>

</dict>

Exclusion options

Allow non-https data transfer

Page 30: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Can also disable App Transport Security for all unspecified URLs, allows arbitrary data access when the endpoint is unknown

Turn off ATS by default

<!-- Turn off ATS in iOS9 --><key>NSAppTransportSecurity</key><dict>

<key>NSAllowsArbitraryLoads</key><true/>

</dict>

Should then turn ATS back on for known endpoints by including specific URL endpoint definitions with this key set to false

Page 31: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v UIApplication.SharedApplication.CanOpenUrl can now only check for specific URL schemes listed in info.plist, all unlisted schemes always return false even if the associated app is installed

CanOpenUrl whitelisting

<key>LSApplicationQueriesSchemes</key><array>

<string>fbapi</string><string>fb-messenger-api</string><string>fbauth2</string><string>fbshareextension</string>

</array>

Support Facebook URLs for login, share, etc.

This change does not impact system-provided URLs such as http:, https:, tel:, etc.

Page 32: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

v Using UIStackView in iOS9

v Adding 3D Touch to your apps

v Adding support for iOS9 Multitasking to your iPad apps

Other Lightning Lectures

Page 33: Updating your Xamarin.iOS apps to iOS9 - Microsoftxamarinuniversity.blob.core.windows.net/lightninglectures/Updating... · v Xamarin iOS Designer does not support the new UI features

Thank You!

//

Mark Smith | [email protected]