iOS8 under Locationmanager and nsnotification use

Source: Internet
Author: User

    1. 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

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.