IOS8 location-based message notification for new features Uilocalnotification

Source: Internet
Author: User


Apple officially unveiled its new IOS8 operating system on the WWDC2014.

The interface on the iOS8 and iOS7 compared to small changes, but in the functional aspects of intact.

IOS8 updated and disclosed a very many interfaces, among which there is a local message notification uilocalnotification, we certainly are not unfamiliar.

However, it was optimized and improved in iOS8.

Now it is able to initiate message notifications based on geographic location, that is, we set a coordinate (latitude and longitude) and radius (range) in the app, and when the device with the app enters the area, the app sends a message notification.


detailed operations such as the following:
1. To import the class library we need corelocation.framework


2. Register location information to obtain the user's authorization

Cllocationmanager *locman = [[Cllocationmanager alloc] init];locman.delegate = self;//Request Authorization to track the User ' s Location[locman requestwheninuseauthorization];
also configure the plist file at the same time

When the last sentence is executed, the user will receive a system prompt and consent to the app being authorized.




3. The app will be callback after obtaining the authorization

-(void) Locationmanager: (Cllocationmanager *) Manager    Didchangeauthorizationstatus: (clauthorizationstatus) Status {   //check status to see if we ' re authorized   BOOL canuselocationnotifications =         (Status = = Kclauthoriza Tionstatusauthorizedwheninuse);   if (canuselocationnotifications) {       [self startshowinglocationnotifications];    }}
notification in callback method
-(void) startshowingnotifications {uilocalnotification *locnotification = [[Uilocalnotification alloc]    INIT];    Locnotification.alertbody = @ "you have arrived!";    Locnotification.regiontriggersonce = YES;                                   Locnotification.region = [[Clcircularregion alloc] Initwithcenter:loc_coordinate    Radius:loc_radius Identifier:loc_identifier]; [[UIApplication sharedapplication] schedulelocalnotification:localnotification];} -(Instancetype) Initwithcenter: (cllocationcoordinate2d) Center//region central latitude and longitude//                              radius: (cllocationdistance) Radius//area radius range//                         IdentiFiER: (nsstring *) identifier; The only descriptive narrative of the notice

4. A message notification is triggered after a certain area has been reached. App callback method after receiving message
-(void) Locationmanager: (Cllocationmanager *) Manager didenterregion: (clregion *) region{NSLog (@ "%s", __func__);} -(void) Application: (UIApplication *) application didreceivelocalnotification:    (uilocalnotification *) notification{    clregion *region = notification.region;    if (region)    {       [self tellfriendsuserarrivedatregion:region];    }}

Note:
Check out the official documentation to learn about many other uilocalnotification new APIs.
The service requires the registration of location information;
Assume that location information is disabled. This method application:didreceivelocalnotification: it will not be called.



IOS8 location-based message notification for new features Uilocalnotification

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.