App with iphone 6/plus and iOS 8:10 tips

Source: Internet
Author: User

App with iphone 6/plus and iOS 8:10 tips 

IPhone 6iOS 8 Adapter

(Original: Raywenderlich Jack Wu Translator: @TurtleFromMars)

The Holidays! To celebrate the festive season, look at this little piece of the geek poem I wrote to this article:

"Keynote Eve, no one knows, new API can debut
Expectations for Siri, Touch ID hope
And at the moment iOS 8 crashed, shocked the audience
Expand, swift,metal, a whole bunch of
General storyboard, who would have imagined
In the midst of cheers, someone began to wander
The existing apps, the adaptation problem is really melancholy
But don't worry, because this tutorial will talk to you about
New APIs and screen sizes to help your app Glow Radiant
Follow 10 tips to be enlightened
IOS 8 Meng Meng da! Well...... Old Duck fan soup? ”

Regardless of how the poem is written, go to the next-10 tips for adapting your app to iOS 8 and new devices-just in time for the holidays! :]

Ready to start

You might think, "I've been walking my app on the iphone 6 Plus, it doesn't look like a problem." Yes, your app should be the same as it was originally, but that doesn't mean you can stop it!

Let the existing app run in zoom mode (scale mode), which Apple has done well, and the app is simply magnified to fit the larger screen. A casual glance, it seems, but you will find the status bar above also become larger. Now you must want your app to run in full screen mode, with the truth in the Picture:

Full screen mode allows your app to display more information in the same screen space. Note that the status bar is not the same size. In this picture, the text may look very small, but it looks just right on the Retina HD screen.

Now that you're ready to fit in full-screen mode, the question is: Do you want to give up support for iOS 7?

You always have to make the final decision, but here are a few things to consider:

    • IOS 7 Users can still get the current version on the App Store.

    • The minimum version of the operating system for large screen devices (iphone 6 and iphone 6 Plus) is iOS 8.

    • Although the adoption rate for iOS 8 was lower than that of iOS 7 a year earlier, it was more than 60%.

    • A cool new API. :]

Well, now that you've decided, let's move on to three bars to get your app to fit 10 tips for IPhone 6,iphone 6 Plus and iOS 8.

Note: If you choose iOS 7 for the updated target system, you can still use the new API. For information on how to support different iOS versions and devices in the same app, see Support for different iOS versions and devices.

First section – Support for new screen sizes 1th: Choose Adaptive Layout and general storyboard

If your app is already using storyboard and auto Layout, it's a hassle, and it's easy to work with. If not, when? The Size Class relies on Auto Layout and Universal Storyboard (Universal Storyboard), and it's clear that Apple is clearly showing that Storyboard is a big hub for future iOS apps.

And, without this, the newest SDK WatchKit simply can't get up.

The good news is that if you haven't chosen one, Raywenderlich.com has several excellent tutorials on storyboard and auto layout. I really liked these few:

    • Swift Language Storyboard Tutorial part 1th

    • Swift Language Storyboard Tutorial part 2nd

    • Swift language auto layout Getting Started Tutorial part 1th

    • Swift language auto layout Getting Started Tutorial part 2nd

To start implementing an adaptive layout, the first step is to convert the existing storyboard into a generic storyboard--, a storyboard that can handle any screen size interface.

All you have to do is click! Open your storyboard and select the use Size Classes in the Info Panel (command+option+1) Information pane:

You will notice that your view has become a square. Don't get too excited, that doesn't mean your app can now support a BlackBerry Passport phone, which is just a typical size for any screen size.

All the constraints should be kept intact and there is no real change. You can confirm this by using the newly added preview (preview) mode in the Assistant editor (secondary editor).

What you can do now is to set the constraints separately for different size categories. To learn more about adaptive layouts, dimension collations, and general storyboard, see Getting Started with adaptive layouts.

Note: If your app is a universal app, you may have a separate storyboard for the iphone and ipad interface. Here are two options:

    1. Continue to use separate storyboard. Just storyboard the iphone, or convert all the storyboard into a generic storyboard, and still fit the iphone and ipad separately.

    2. Chop off the re-practice! Change to a general storyboard! This will only require maintenance of a storyboard, but the workload of this scheme is not small. Currently there is no tool in Xcode that will help you refactor, but you can only rely on yourself.

2nd: Open the Full screen display mode and the splash screen file

Recall that the full-screen mode is much more cool than the zoom-in display mode, and the work you just completed is just a self-adapting layout, so what's the benefit if your app doesn't run in full-screen mode? Fortunately, it's quite easy to turn on full screen mode with a little extra benefit!

Apple says:

At run time, the system will look for storyboard launch screen file (Storyboard splash screen files), if you want to let the system know your app supports iphone 6 's different size, please in your app The bundle contains a Storyboard splash screen file. If such a file exists, your app will be judged to be specifically adapted to iphone 6 and iphone 6 Plus and run in full-screen mode.

Stop! Start screen Storyboard? Perhaps you will ask: "As the name implies ... I don't have to prepare 20 splash screen pictures anymore? ”

yes! Sure and sure!

Let's get started, add a new file to your app from new files. In iOS > User Interface , there is a new file type Launch screen, a veritable, add a new splash to your app! The default splash screen created by Xcode is a bit shabby.

Interesting, we talked about in front of the storyboard, this next xcode for you to create a xib file. Quickly open this xib, delete the ugly to explode the label, dress it as you like it. If you want it to be the same as before, just add a boot image UIImageView .

Finally, go to Project Synthesis Setup (General Settings) like this to select your new xib file for Launch screen files:

Build your app and run it on the iphone 6 Plus simulator, with the new splash screen and the awesome full screen display mode, and enjoy it.

Note: If you want to support iOS 7 and/or older system versions, you still have to provide a 4-inch boot image. Otherwise your app will display in 3.5-inch mode.

3rd: New generation Retina display and @3x pictures

The IPhone 6 Plus features a new generation Retina HD display with 401 PPI. To adapt to this high resolution, you need to provide 3 times times the resolution of the picture. Just like @2x pictures, all you have to do is provide @3x images, and iOS will help you load the correct images.

Note: The IPhone 6 is also equipped with a Retina HD display, but its pixel density is the same as the previous Retina iphone, and still loads @2x's image resources.

Your app can run in full-screen mode! Hi, Big Ben!

But there are still a lot of problems to deal with, please don't leave!

Section II – Changes in user licenses

Users will love the improvements in the privacy settings of iOS 8.

Unfortunately, if used improperly, your app may crash.

In this section, you will fix these issues to reassure and delight the user.

Looking down, here are three tips for this section:

4th: Fix location License

IOS 8 introduces two new permissions for requesting user locations: One receives updates only when the app is running, and the other can receive updates when the app is not running.

Previously, iOS automatically asked users for app permissions when they started monitoring locations. This has changed in iOS 8, and you need to explicitly request user consent before you start updating your location.

To do this, if the current license status is unclear, you need to call Cllocationmanager requestWhenInUseAuthorization or requestAlwaysAuthorization method.

Add the call to the Cllocationmanager before calling the startUpdatingLocation method. It's so simple:

Self.locationmanager = [[Cllocationmanager alloc] init];  Self.locationManager.delegate = self; if ([cllocationmanager authorizationstatus] = = kclauthorizationstatusnotdetermined) {[Self.locationmanager  Requestwheninuseauthorization]; } [Self.locationmanager startupdatinglocation];

Last step: Add Nslocationwheninuseusagedescription or Nslocationalwaysusagedescription to the new key in the app's Info.plist Then enter a string that tells the user to request permission. For example: "Show items near you need to get your location." ”

5th: Repair Notification Registration

In iOS 8, user notification licenses are subject to change, primarily to support actionable notifications. The old version of the API is not valid in iOS 8 and should not be used.

Now that the notification license is divided into two tiers, your app must first request permission to display a specific type of notification, and after a successful user license, you need to request permission to receive a remote notification.

The previous practice is -application:didFinishLaunchingWithOptions: to call inside -registerForRemoteNotificationTypes: to receive the delegate callback check status. If you write this in iOS 8, you'll find that you haven't called the delegate method at all.

This is because you need to request a first-level user notification permission first. The following is a simple example in Appdelegate:

-  (BOOL) Application: (uiapplication *) Application didfinishlaunchingwithoptions: (NSDictionary  *) launchoptions {  // 1  uiusernotificationsettings *settings =  [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |  Uiusernotificationtypebadge | uiusernotificationtypesound categories:nil];  // 2   [application registerusernotificationsettings:settings];   return yes}  -  (void) application: (uiapplication *) Application didregisterusernotificationsettings: ( uiusernotificationsettings *) notificationsettings {  // 3  if  ( Notificationsettings.types != uiusernotificationtypenone)  {    // 4     [application registerForRemoteNotifications];  }} // 5-  (void) Application: (uiapplication *) APPLIcation didregisterforremotenotificationswithdevicetoken: (nsdata *) devicetoken {  //  ...  (no changes needed)} -  (void) application: (uiapplication *) application  didfailtoregisterforremotenotificationswitherror: (nserror *) error {// ...  (no  changes needed)}

One more callback than before, here is a brief explanation of these steps:

    1. First, create a UIUserNotificationSettings setting object that defines the notification type for the app display, which also includes the class that defines the operation (categories).

    2. Called -registerUserNotificationSettings: to pass in the Settings object. This will request permission from the user.

    3. When the user gives a response, the new delegate method -application:didRegisterUserNotificationSettings: is called. The object passed in here is not necessarily the same as the notificationSettings one passed in in the second step. This only describes the permissions that are granted by the user. View types to verify that the user has licensed those permissions.

    4. If a user license is successfully obtained, it can now be called -registerForRemoteNotifications . Note that this method no longer accepts parameters. The settings information is now captured by the set object, where the request accepts remote notifications only.

    5. After that, you can still get the device token using the same callback as usual.

6th: Friendly Two-time license request

If the user rejects the license when asked for the first time, then no more pop-up questions will occur. If a user rejects a required license, the common scenario is to display an error page in the app or to tell the user how to turn on the appropriate permission in the privacy settings. The practice is somewhat clumsy, and many apps have been poorly rated.

IOS 8 provides uiapplicationopensettingsurlstring to simplify this part of the work. The characteristic of this string constant is that passing it -openURL: into the method directly allows the user to jump to the settings of the corresponding app. As a result, asking for permission saves a lot of work.

The correct use of posture is to include this line of code in a button or prompt action (action):

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]];

Section three – adaptation Dogo Katsuragi talk

Now that your app is ready for iOS 8, welcome to the new API for iOS 8 waiting for you.

The feature adaptation is finally done, the app works perfectly, and now it's fun to start:]

7th: Release the power of Swift language

The most obvious benefit of using the swift language is reducing the number of files and the number of lines of code. You do not have to rewrite any existing code with Swift, even in existing projects you can start writing Swift code directly in new classes and new files.

Here are some recommendations to ensure the peaceful coexistence of swift and Objective-c in the project:

    1. When you first add a swift file in your project, Xcode creates the bridge header file for you (bridging header). Please allow Xcode to handle this.

    2. If you want to use the Objective-c class in a swift file, #import import the objective-c header file into the Bridge Connector file with a standard statement.

    3. If you want to use the Swift class in your objective-c code, import the Include header file (umbrella header) ProductModuleName-Swift.h into the appropriate .m file, where Productmodulename is the module name, in most cases, the project name, But it's better to go over the project setup and check it out carefully.

    4. Make sure that your swift class inherits either a Objective-c class (for example NSObject ) or the use of a @objc class name and a method name.

To learn more about Swift, see our Swift Tutorials and the list of iOS tutorials, most of which have been updated for Swift or talked about Swift.

If you want to learn more about how to work together with Swift and Objective-c, see Apple's Guide to using Swift in collaboration with Cocoa and objective-c.

8th: Important API fallback or update information

IOS 8 has updated some of the basic components of cocoa touch. , there is a UIAlertView UIActionSheet UISearchDisplayController more satisfactory alternative to use, and UIPresentationController in the view controller rendering process will play a popular role.

Uialertcontroller replaces UIAlertView and UIActionSheet provides an elegant interface based on block callbacks. As an example:

Uialertcontroller * alert = [Uialertcontroller alertcontrollerwithtitle:@ ' is you sure? ' message:@ ' Once deleted this item Cannot be recovered. "Preferredstyle:uialertcontrollerstylealert"; [Alert addaction: [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault handler:^ (UIAlertAction * Action) {[self deleteItem]}]; [Alert addaction: [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:{}]; [Self Presentviewcontroller:alert animated:yes completion:nil];

As you can see, no longer have to specify delegate, want to render on the call -presentViewController: , look at how comfortable, is this smell. UIAlertControllerIt also brings some new features, such as a multi-button and a simple configuration of a text box.

For more information, please refer to this article on Nshipster: Uialertcontroller (Chinese version).

Uipresentationcontroller gives you the freedom to render the view controller. Manipulate the rendered hue, position, and animation in an elegant, reusable way.

To learn more about rendering controllers (Presentation Controller), refer to the official documentation or the sixth chapter of the iOS 8 tutorial, "Introduction to Presentation controller."

9th: New Cool visual effects

The blur effect is one of the most popular new features of iOS 7. Apple has finally exposed this API in iOS 8: The new Uivisualeffectview and Uivibrancyeffectview classes!

Uivisualeffectview is an effective way to weaken the background, and Uivibrancyeffectview will make the foreground more colorful. These two classes have been optimized, but if abused, they slow down your app's performance and must be used with caution.

To get started with iOS 8 visuals, take a look at our iOS 8 visual effects tutorial.

10th: New Choices, the world

The main content of this tutorial is how to get your app to run on iOS 8 and follow these tips to get it done! Good (bad?) The message is that this is just the beginning, and IOS 8 brings too many things!

There are many ways to extend the app's functionality in iOS 8, turning the past impossible into a possibility. Here are a few references for your app:

    • Use WatchKit to create a watch extension for your app.

    • Create Today Extension to let users follow information in notification hubs.

    • Use document Provider to implement file sharing between applications.

    • Adds an action action to the notification.

    • Integrated Touch ID makes it easy for users to authenticate.

To learn more about iOS 8 and WatchKit, see the iOS 8 tutorial and the WatchKit tutorial.

Go?

IOS 8 has opened the door to more features than ever before.

With these new tools, there seems to be a new beginning again.

I hope you enjoy this article and benefit from these tips.

Friends, go ahead and use code to create laughter! :]

This tutorial content worlds, I wish I express enough clarity.

The following links are available for readers to refer to:

    • Support for different iOS versions and devices

    • Storyboard Tutorials

    • Auto Layout Tutorial

    • Our collection of Swift tutorials

    • Our iOS 8 tutorial set

    • Working with cocoa and objective-c in conjunction with Swift

    • The Uialertcontroller on the Nshipster

    • Uipresentationcontroller Official documents

    • IOS 8 Visual effects

    • IOS 8 Tutorials

    • WatchKit Tutorials

    • Swift Tutorial Set

(This article is for Cocoachina organization translation, this translation right belongs to the translator, without permission to prohibit reprint.) )

App with iphone 6/plus and iOS 8:10 tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.