Iphone 6&6p,ios8 Adaptation Summary

Source: Internet
Author: User

Tagged with: iOS iphone 6 iphone 6p for iOS 8

I. Problems encountered in IOS8 adaptation

1. Unable to locate
Tick settings-Privacy-Location Services-your app-use the application period (always)
When you open the app, you'll see that you've ticked off the program (always) and canceled it.

The original iOS8 need some method.
If you need to locate only in the foreground, you need to call Requestwheninuseauthorization before calling Startupdatinglocation
If you need to locate in front of the background, you need to call Startupdatinglocation before calling Requestalwaysauthorization
Also add nslocationwheninuseusagedescription or nslocationalwaysusagedescription fields to the Plist file, and the value write "need to be located" on it, or it can be other, This hint text "needs to be located" will be displayed when asking the user for authorization.

1.if ([[[[Uidevice Currentdevice] systemversion] floatvalue]>= 8.0) {

2.[_locationmanager Requestwheninuseauthorization];

3.}

4.

5.[_locationmanager Startupdatinglocation];


2, push does not work

01.if ([[[[Uidevice Currentdevice] systemversion] floatvalue]>= 8.0) {

02.[app Registerforremotenotifications];

03.

04.UIUserNotificationSettings *settings =[uiusernotificationsettings settingsfortypes:

05.UIRemoteNotificationTypeAlert

06.| Uiremotenotificationtypebadge

07.| Uiremotenotificationtypesoundcategories:nil];

08.[appregisterusernotificationsettings:settings];

09.

Ten.} else {

11.[app Registerforremotenotificationtypes:

12.UIRemoteNotificationTypeAlert

13.| Uiremotenotificationtypebadge

14.| Uiremotenotificationtypesound];

15.}

iOS8 registration push is two steps away,

1. Notice of Registered User

Uiusernotificationsettings *settings =[uiusernotificationsettings settingsfortypes:

Uiremotenotificationtypealert

| Uiremotenotificationtypebadge

| Uiremotenotificationtypesound Categories:nil];

[[UIApplication sharedapplication] registerusernotificationsettings:settings];

2 "After the user notification registration succeeds, the following callback will be taken, in the callback function to push the registration:

#if __iphone_os_version_max_allowed >= 80000

-(void) Application: (UIApplication *) Applicationdidregisterusernotificationsettings: (uiusernotificationsettings* ) notificationsettings

{

[[UIApplication sharedapplication] registerforremotenotifications];

}

#endif

3 "The next step is to go back to the previous push callback:

-(void) Application: (UIApplication *) Applicationdidregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken//Successful callback

-(void) application: (uiapplication*) Applicationdidfailtoregisterforremotenotificationswitherror: (NSError*) error Failure callback

to determine the push-open switch, iOS8 Previous code:

[[UIApplication Sharedapplication]enabledremotenotificationtypes]!=uiremotenotificationtypenone;

iOS8 need to change to the following code:

[[UIApplication Sharedapplication]isregisteredforremotenotifications]

3. The layout calculation of some system controls is deferred to the drawing when it occurs:

As an example:

UIButton * button = [Uibuttonbuttonwithtype:uibuttontypecustom];

[BUTTONSETTAG:I];

[ButtonsetTitle:siteData.info.title

Forstate:uicontrolstatenormal];

[Button.titlelabel Setlinebreakmode:nslinebreakbytruncatingtail];

[Buttonsettitlecolor:[uicolor colorwithhexvalue:0x000000]

Forstate:uicontrolstatenormal];

[Buttonsettitlecolor:[uicolor COLORWITHHEXVALUE:0XFFFFFF]

Forstate:uicontrolstatehighlighted];

[Buttonsettitlecolor:[uicolor COLORWITHHEXVALUE:0XFFFFFF]

Forstate:uicontrolstateselected];

[Button.titlelabel Setfont:[uifont systemfontofsize:14];

[Button Setbackgroundcolor:[uicolorclearcolor]];

Uiimage*image = [UIImage imagenamed:@ "Sourceselect"];

Image =[image Resizableimagewithcapinsets:uiedgeinsetsmake (4, 2, 4, 2)];

[Buttonsetbackgroundimage:nil

Forstate:uicontrolstatenormal];

[Buttonsetbackgroundimage:image

Forstate:uicontrolstatehighlighted];

[Buttonsetbackgroundimage:image

Forstate:uicontrolstateselected];

Button.exclusivetouch = YES;

button.selected = NO;

uiimage*tmpimg = [Utility imagefromcolor:[uicolor Clearcolor]

Rect:cgrectmake (0, 0, 47, 60)];

[Buttonsetimagewithurl:[nsurl URLWithString:siteData.info.logoURL]

PLACEHOLDERIMAGE:TMPIMG];

Ios8layout will delay to render, this place needs to be calculated coordinates, so you need to manually force layout

[buttonsetneedslayout];

[Button layoutifneeded];

Nsintegertitlewidth = Cgrectgetwidth (button.titleLabel.frame);

4, some system control animation will have a delay phenomenon:

Example:

[Uiviewbeginanimations:nil Context:nil];

[Uiviewsetanimationduration:duration];

[ProgressBar Setalpha:alpha];

Progressbar.frame = frame;

[UIView commitanimations];

The above code is the browser progress bar changes animation, in the IOS7 work well, in the Ios8 there will be a progress backward strange phenomenon.

5. UITableViewCell has a default size (320,44):

In-(ID) Initwithstyle: (Uitableviewcellstyle) Stylereuseidentifier: (NSString *) Do not rely on self.frame or self.contentView.frame in the Reuseidentifier method, because size at this time is the default size (320,44).

There are two ways to solve this problem,

1>> rewrite the Setframe method,

-(void) Setframe: (CGRect) frame

{

Frame.size.width=view_width;//view_width here is the width of the screen when the vertical screen

[Supersetframe:frame];

}

2>> in-(ID) Initwithstyle: (Uitableviewcellstyle) Stylereuseidentifier: (NSString *) Reuseidentifier method to put the wide write to death, Do not write values that are calculated according to Self.frame.width, such as the need to be wide with the screen, with [UIScreen mainscreen].bounds.width,

Ii. problems encountered in iphone6&6p adaptation

1, how to manage the picture, for the 6p picture plus @3x suffix, the system can automatically load the required images for us, but for 6, because 6 and 4/4s/5/5s magnification is the same, if you want to do a picture for 6 alone, the system will not know which picture we want to load. There are two ways of doing this at this time:

1 "To make a man-made agreement, for example, for 6 of the image name plus" _6 "suffix, and then for the uiimage to do an extension:

For example:

+ (Instancetype) Imagenamedfordevices: (nsstring*) ImageName

{

Nsrangeatpos=[imagename rangeofstring:@ "@"];

if (atpos.location!=nsnotfound) {

Imagename=[imagename SubstringToIndex:atPos.location];

}

uiimage* Defaultimage=[uiimage Imagenamed:imagename];

Uiimage* Iphone6image=defaultimage;

if (![ ImageName hassuffix:@ "_6"])

{

Iphone6image=[uiimage imagenamed:[imagename stringbyappendingstring:@ "_6"];

if (!iphone6image) {

Iphone6image=defaultimage;

}

}

Returnvalue_for_universe_device (Defaultimage, Iphone6image, defaultimage);

}

In this case, join us there is a picture for 5s,6,6p there are three versions, respectively named [email protected], [email protected], [email protected],

We just call [UIImage imagenamedfordevices:@ "Home_bar"] in the program, and we can get the corresponding version of the picture according to the device.

2 "Manual write if Else statement, according to the device to write different code to obtain the picture, it is not recommended this practice.

2, how to tailor the needs of specific equipment:

typedef enum

{

IPhoneDeviceTypeIPhone4,

Iphonedevicetypeiphone4s=iphonedevicetypeiphone4,

IPhoneDeviceTypeIPhone5,

Iphonedevicetypeiphone5s=iphonedevicetypeiphone5,

IPhoneDeviceTypeIPhone6,

iphonedevicetypeiphone6p

}iphonedevicetype;

Iphonedevicetype Global_devicetype;

#define IS_IPHONE_5OR_ABOVE (global_devicetype>=iphonedevicetypeiphone5s)

#define IS_IPHONE_6P (global_devicetype==iphonedevicetypeiphone6p)

#define IS_IPHONE_6OR_ABOVE (Global_devicetype>=iphonedevicetypeiphone6)

#define IS_IPHONE_6 (Global_devicetype==iphonedevicetypeiphone6)

#define Value_for_universe_device (a,b,c) ((is_iphone_6p)? (a):((is_iphone_6)? (b):(C)))

Get Device size information

+ (void) Getdevicetype

{

Iphonedevicetype type;

Cgrectbounds=[[uiscreen Mainscreen] bounds];

Cgfloatheight=bounds.size.height;

Cgfloatscale=[uiscreen Mainscreen].scale;

if (height<568) {

type=iphonedevicetypeiphone4s;

}

ElseIf (height<667)

{

type=iphonedevicetypeiphone5s;

}

ElseIf (scale<2.9)

{

Type=iphonedevicetypeiphone6;

}

Else

{

type=iphonedevicetypeiphone6p;

}

Global_devicetype=type;

}

Value_for_universe_device This macro allows us to focus on the device's judgment, greatly simplifying the code, A,B,C can be any type, as long as the a,b,c is guaranteed to be the same type, a is the value of 6P custom, B is the value of 6 custom , C is a value that is customized for a setting of less than 6.

3, related to the screen switch VC, the code is usually used to uiscreen, uiwindow positioning needs to be rewritten, the width of min (width,height), the height of Max (height,width).

4, coordinate dependence law: all coordinates in 1>>viewcontroller should depend on all coordinates in Self.view.bounds;2>>uiview should depend on self.bounds;3>> The coordinates of other cases should depend on the screen size, 1, 2 are relative coordinates, and 3 are absolute coordinates. we should prioritize relative coordinates and use as few absolute coordinates as possible.

5, the overall adaptation principle:1>> first consider horizontal full, vertical according to need to increase the height;

2>> poster, large picture, small window player to eradicate the transverse amplification factor to enlarge the ratio;

3>> poster's internal margin remains unchanged, the distance between the poster and the text remains unchanged, the spacing between text font and text is fine-tuned according to the visual needs;

4>> for those who do not specifically provide iphone6&6p transduction pictures, in order to ensure that the picture is not empty, you need to write frame as large as the size of the picture.

6. Discussion on Adaptation solutions:

There are three types of options:

1>>xib+autolayout;

This scheme is the most ideal adaptation scheme, VC coordinate system at a glance, only need to simple calculation can be adapted to new equipment. The premise is that the source code used to Xib to write VC.

2>> handwriting vc+ handwriting AutoLayout;

Personally think that this scheme is the most cumbersome solution, the first need a large number of coordinate calculations, and then need to understand the VFL syntax very well, to solve the constraints of dependency missing or conflict problems, the result is the coordinate calculation cumbersome and complex, code changes are very large, code increase is very large, not easy to maintain.

3>> handwriting vc+ manual adaptation;

This solution also avoids cumbersome coordinate calculations, but relative to the 2 scenario, there is no need to understand the VFL syntax, or to solve problems such as constrained dependency loss or conflict, with relatively little code churn. This is the kind of solution we are currently using in our project.

Iphone 6&6p,ios8 Adaptation Summary

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.