-
Location Service use
iOS8 before locationservice in app Open
Self.locationmanager = [[Cllocatonmanager alloc] init]
[Self.locationmanager startupdatinglocation];
You need to add Kclauthorizationstatusauthorizedalways to the iOS8, adding it in the Info.plist in the app Nslocationalwaysusagedescription or nslocationwheninuseusagedescription the value of one of the key,value can be filled in arbitrarily, it will be displayed in the dialog box where the fetch location is requested.
Request Get location permission
IOS 8-request Location Services via requestwheninuseauthorization.
if ([Self.locationmanager respondstoselector: @selector (requestwheninuseauthorization)]) {
[Self.locationmanager requestwheninuseauthorization];
} else {
IOS 7-we can ' t use requestwheninuseauthorization--We'll get an unknown selector crash!
Instead, just start updating location, and the OS would take care of prompting the user
For permissions.
[Self.locationmanager startupdatinglocation];
}
Implement the Proxy method, when you get to this permission
-(void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status
{
We only need to start updating location for iOS 8-iOS 7 users should has already
Started getting location updates
if (status = = Kclauthorizationstatusauthorizedalways | |
Status = = Kclauthorizationstatusauthorizedwheninuse) {
[Manager Startupdatinglocation];
}
}
2.ios8 setting permissions to get notifications differs from before
#ifdef __IPHONE_8_0
if(system_version_less_than(@ "8.0")) {
uiremotenotificationtype mytypes = Uiremotenotificationtypebadge | Uiremotenotificationtypealert | Uiremotenotificationtypesound;
[[uiapplication sharedapplication] registerforremotenotificationtypes: Mytypes];
}
Else {
uiusernotificationsettings* notificationsettings = [uiusernotificationsettings settingsfortypes:uiusernotificationtypealert | Uiusernotificationtypebadge | Uiusernotificationtypesound Categories:nil];
[Application registerusernotificationsettings: notificationsettings];
[Application registerforremotenotifications];
}
#else
Uiremotenotificationtype mytypes = Uiremotenotificationtypebadge | Uiremotenotificationtypealert | Uiremotenotificationtypesound;
[[UIApplication sharedapplication] registerforremotenotificationtypes:mytypes];
#endif
Get Remotenotification
-(void) Application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) completionhandler{
Completionhandler (uibackgroundfetchresultnewdata);
NSLog(@ "remote notifation%@", userInfo);
}
// get notifications to push
-(void) Application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) userinfo{
}
Set Setbadgenumber
-(void) Setapplicationbadgenumber: (nsinteger) badgenumber
{
uiapplication *application = [uiapplication sharedapplication];
#ifdef __IPHONE_8_0
//compile with Xcode 6 or higher (IOS SDK >= 8.0)
if(system_version_less_than(@ "8.0"))
{
Application. Applicationiconbadgenumber = badgenumber;
}
Else
{
if ( [ self checknotificationtype: Uiusernotificationtypebadge])
{
NSLog(@ "badge number changed to%d", badgenumber);
Application. Applicationiconbadgenumber = badgenumber;
}
Else
NSLog(@ "Access denied for Uiusernotificationtypebadge");
}
#else
//compile with Xcode 5 (IOS SDK < 8.0)
Application.applicationiconbadgenumber = Badgenumber;
#endif
}
This article is from the "Enjoy programming" blog, so be sure to keep this source http://demidroid.blog.51cto.com/2954092/1559228
iOS8 under Locationmanager and nsnotification use