Changes to the positioning and message pushing APIs after ios8, ios8api
1. positioning is positioning, maps are maps, CLLocation is specifically responsible for locating or obtaining location information in iOS, and MAPkit is specifically responsible for displaying the map
Location Manager (CLLocationManager): obtains and monitors user location changes.
// [Note] the location manager must be written as an attribute. If the attribute is not output from the stack, no more
_ Manager = [[CLLocationManager alloc] init];
// Set the Location Manager Proxy <CLLocationManagerDelegate>
_ Manager. delegate = self;
// Set the minimum update location
_ Manager. distanceFilter = 50366f; // The unit is meter"
// Set the positioning accuracy. The higher the accuracy, the more expensive the power consumption.
_ Manager. desiredAccuracy = kCLLocationAccuracyBest;
[Note:] Apple modified the location authorization protocol in ios8. this means that your original app may not be able to be located on ios8. Currently, the best way is to call the IOS8 positioning authorization API to obtain user authorization when the app is started, so do not modify it elsewhere, as shown below:
[_ Manager requestAlwaysAuthorization];
[_ Manager requestWhenInUseAuthorization];
[Note:] You also need to add NSLocationAlwaysUsageDescription and NSLocationWhenInUseDescription attributes in the plist file. The value can be blank;
// Let the location manager take effect and start updating the location changes
[_ Manager startUpdatingLocation];
2. Modify the message push API
Third-party push servers commonly used in iOS include Aurora and pigeon.
We can see that:
1. register the notification in your app first. Do not register the notification time zone before and after iOS8. The differences are as follows:
// [Note] If your system is iOS 8 or later
If ([[UIDevice currentDevice]. systemVersion floatValue]> = 8.0 ){
// Set the form of user notification
[[UIApplication sharedApplication] registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes :( UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories: nil];
// Register remote notification application device token
[[UIApplication sharedApplication] registerForRemoteNotifications];
} Else {
// [Note] register a remote notification, which includes text, badge, and sound.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes :( UIRemoteNotificationTypeAlert | uiremotenotiftypetypebadge | uiremotenotiftypetypesound)];
}
// The data generated after the registration of the Pigeon Service will be sent to the pigeon server. Only after registration can the pigeon server push messages to the app
+(void)startApp:(uint32_t)appId appKey:(NSString *)appKey;
Parameter description:
Access Id: the Access Id obtained when the app is registered through xg.qq.com.
Access key: the Access key obtained when the app is registered through xg.qq.com.
For example, [XGPush startApp: 1234567 appKey: @ "IF3W91AV58NC"];
2. The device token that the APNS server returns to us
-(Void) application :( UIApplication *) application didRegisterForRemoteNotificationsWithDeviceToken :( NSData *) deviceToken {
// Register the device identifier with the pigeon
// Your real machine is available in the pigeon's device list after registration
NSString * token = [XGPush registerDevice: deviceToken];
NSLog (@ "token: % @", token );
}
3. The application sends the device token to the PUSH server program.
4. The server program sends a message to the APNS service.
5. The APNS Service sends messages to the iPhone application.