IOS8 Interactive notification of new features

Source: Internet
Author: User

IOS8 previous remote notification presumably everyone is very familiar with, here do not do too much introduction, directly introduce the interactive remote notification in iOS8.


One, by calling [[uiapplicationsharedapplication] Registerforremotenotifications]; To achieve

Application:didregisterforremotenotificationswithdevicetoken: and application: Didfailtoregisterforremotenotificationswitherror: The callback


Second, set uiusernotificationaction and uimutableusernotificationcategory

Settings for uiusernotificationaction:

Uimutableusernotificationaction *cancelaction = [[Uimutableusernotificationaction alloc] init]; [Cancelaction setidentifier:@ "Cancelnotificationactionidentifier"]; [Cancelaction settitle:@ "Cancel"]; [Cancelaction Setactivationmode:uiusernotificationactivationmodebackground]; [Cancelaction Setauthenticationrequired:yes]; [Cancelaction Setdestructive:yes];

Identifier

Unique identifier of User Notificaton Aciton

Title

Display title of User Notificaton Aciton button

Activationmode

Uiusernotificationactivationmodeforeground activates the app and opens to the front desk to show

Uiusernotificationactivationmodebackground in the background to activate the app, the test found that if the app is not launched (the app is not open in the background), then perform this mode of operation , the app will not open If the app is already in the foreground, the app is still in the foreground when it's done in this mode.

Authenticationrequired

If set to Yes, the device must be unlocked when performing this operation, instead of unlocking it.

If the activationmode is uiusernotificationactivationmodeforeground , Authenticationrequired is treated as yes.

Test found that if the user device has a password, the lock screen when the authenticationrequired set to Yes when the user needs to enter a password, if set to No does not require the user to enter a password, if the user device does not have a password, then regardless of the settings do not need to enter a password.

Destructive

Indicates whether the action button is red, which is highlighted only when the lock screen and swipe left from the notification center appear, without the highlight when the top message is displayed.


Settings for Uimutableusernotificationcategory:

Uimutableusernotificationcategory *notificationcategory = [[Uimutableusernotificationcategory alloc] init]; [Notificationcategory setidentifier:@ "Notificationcategoryidentifier"]; [Notificationcategory setactions:@[acceptaction, cancelaction]                      forcontext: Uiusernotificationactioncontextdefault];
<strong><em>identifier</em></strong>
The category is unique, and the value of identifier must be the same as the category value in payload (pushed from the server to the client's content).

Actions

Uiusernotificationaction Array, if set to nil, the action button will not be displayed.

Context

Uiusernotificationactioncontextdefault The default context of the notification operation, in which case you can specify 4 custom actions. (not yet verified)

Uiusernotificationactioncontextminimal the minimum context of a notification operation, in which case you can specify 2 custom actions. (not yet verified)


Third, setuiusernotificationsettings

Uiusernotificationtype notificationtypes = (uiusernotificationtypealert|                                            uiusernotificationtypesound|                                            Uiusernotificationtypebadge); Nsset *categoriesset = [Nsset setwithobject:notificationcategory]; Uiusernotificationsettings *notificationsettings = [Uiusernotificationsettings settingsfortypes:notificationtypes                                                                                     Categories:categoriesset];
Set the type and category supported by the notification, there is no difficulty here, but more explanation.

Iv. Notice of registration registerusernotificationsettings

[[UIApplication sharedapplication] registerusernotificationsettings:notificationsettings];
Registering notifications in IOS8 by using the above method can be differentiated according to the operating system version

V. Handling CALLBACK Events

-(void) Application: (UIApplication *) application Handleactionwithidentifier: (NSString *) identifier Forremotenotification: (nsdictionary *) userInfo Completionhandler: (void (^) ()) completionhandler{    if ([ Identifier isequaltostring:@ "Cancelnotificationactionidentifier"])    {        NSLog (@ "You chose Cancel action.");    else if ([identifier isequaltostring:@ "Acceptnotificationactionidentifier"])    {        NSLog (@ "You chose accept action.");        if (Completionhandler)    {        completionhandler ();    }}
<strong><em>application</em></strong>
<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " > The object receiving the notification </span>

Identifier

The only indication of uiusernotificationaction

UserInfo

Payload's content

Completionhandler

This method must be called at the end after the specified operation has been performed


The paload I used to test was

{    aps =     {        alert = "Thank you very much";        badge = 1;        Category = Notificationcategoryidentifier;        Sound = "PING.CAF";    };}


IOS8 Interactive notification of new features

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.