IOS (local notification and remote notification)

Source: Internet
Author: User

There are two types of IOS push notifications: Local push, remote push.

Local push: When the internet is not needed, push is sent by the app, often at a moment's notice, such as an alarm clock. The limitation of local delivery is that it cannot be notified when the app is in the background or when it exits.

Remote push: APNs and third-party push, third-party push finally also need APNs forwarding,

Local Push implementation
Registration NOTICE:

    

float sysver = [[Uidevice currentdevice].systemversion floatvalue];    if (Sysver <) {        //Set Notification type bullet box, foot tag, sound        uiusernotificationsettings* setting = [uiusernotificationsettings Settingsfortypes:uiusernotificationtypealert | Uiusernotificationtypebadge | Uiusernotificationtypesound Categories:nil];        [[UIApplication sharedapplication] registerusernotificationsettings:setting];    } else{        unusernotificationcenter* Center =[unusernotificationcenter Currentnotificationcenter];        [Center requestauthorizationwithoptions: (Unauthorizationoptionalert | Unauthorizationoptionbadge) completionhandler:^ (BOOL Granted, Nserror * _nullable error) {            if (granted) {                NSLog (@ "Notification registration succeeded");}}        ];    }

  

Send notification:
    

  

float sysver = [[Uidevice currentdevice].systemversion Floatvalue];        if (Sysver <) {uilocalnotification* local = [[Uilocalnotification alloc] init];                Assign values to these attributes to let the notification have a specific content [email protected] "Nautical king: one Piece";        A specific time to show () nsstring* datestr = @ "2016-12-01 16:30:00";        nsdateformatter* dateformatter = [[NSDateFormatter alloc]init];                Dateformatter.dateformat = @ "Yyyy-mm-dd hh:mm:ss";                Local.firedate=[nsdate datewithtimeintervalsincenow:60];                Slide the unlocked text (a small line below the push notification message) Local.alertaction [email protected] "";                There is a sound to the voice, no sound with the default [email protected] "uilocalnotificationdefaultsoundname";                Set icon in the upper right corner of the digital local.applicationiconbadgenumber=1;                User information [email protected]{@ "name": @ "Nautical King", @ "content": @ "one Piece" @ "time": @ "20161201"}; 3: Customizing a notification [[UIApplication SharedaPplication]schedulelocalnotification:local];        }else{unmutablenotificationcontent* content = [[Unmutablenotificationcontent alloc] init];        Content.title = [NSString localizedusernotificationstringforkey:@ "Hello title" Arguments:nil];        Content.body = [NSString localizedusernotificationstringforkey:@ "Hello body" arguments:nil];                Content.sound = [Unnotificationsound defaultsound]; Set notification time untimeintervalnotificationtrigger* trigger = [Untimeintervalnotificationtrigger triggerwithtimeinterval:5        Repeats:no]; unnotificationrequest* request = [unnotificationrequest requestwithidentifier:@ "notificationidentifier" content:                Content Trigger:trigger];        unusernotificationcenter* Center = [Unusernotificationcenter Currentnotificationcenter]; [Center Addnotificationrequest:request withcompletionhandler:^ (nserror * _nullable error)    {                                }]; }

Remote Push implementation

The process by which the server sends a push to the client:

                  

Each request has a device token, APNs through the device token to identify the device and the app, each time the app runs, it sends the device token to the server, the server then sends the push with the device token, and the device token is changed only when the push settings change, only APNs can decode the device token.

    

Server and APNs connection process:

    

                            

Dizziness, this still depends on the official document:https://developer.apple.com/library/prerelease/content/documentation/NetworkingInternet/ CONCEPTUAL/REMOTENOTIFICATIONSPG/APNSOVERVIEW.HTML#//APPLE_REF/DOC/UID/TP40008194-CH8-SW1

Carrier Pigeon Use Flow:

1, configure the true Machine Debug certificate, push test certificate (degree Niang)

2. Sign up for iOS push

 float sysver = [[[Uidevice Currentdevice] systemversion] floatvalue]; if (Sysver < 8) {[[UIApplication sharedapplication] Registerforremotenotificationtypes: (Uiremotenotificationtypea Lert | Uiremotenotificationtypebadge |    Uiremotenotificationtypesound)]; }else{#if __iphone_os_version_max_allowed >= _iphone80_ uimutableusernotificationcategory *categorys = [[UIMutab]        Leusernotificationcategory alloc] init]; Uiusernotificationsettings *usersettings = [uiusernotificationsettings settingsfortypes: uiusernotificationtypebadge| uiusernotificationtypesound| Uiusernotificationtypealert Categories        : [Nsset Setwithobject:categorys]];        [[UIApplication sharedapplication] registerusernotificationsettings:usersettings]; [[UIApplication sharedapplication] registerforremotenotifications]; #endif} 

3, registration equipment information (Devicetoken)

-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {    //Register device NSString * devicetokenstr = [Xgpush Registerdevice:devicetoken];        Print Gets the Devicetoken string NSLog (@ "Devicetokenstr is%@", devicetokenstr);}

3. Registered Carrier Pigeon

[Xgpush startapp:@ "10086" appkey:@ "key"];

Set up your account
[XGPush setAccount:@"123456"];

Push statistics

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{     [XGPush handleReceiveNotification:userInfo]; }


 

IOS (local notification and remote notification)

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.