iOS9 development of New notice behavior

Source: Internet
Author: User

Apple iniOS8When you publish, you can enter text and reply directly to the notification box when you receive a text message, but this feature is not really open to developers.

iOS9New User notification behaviorUiusernotificationactionbehaviortextinput,Apple has finally opened up this cool feature to us.


the specific way is:

1.To set notification behavior:
//1.create variable notification behavior
uimutableusernotificationaction * ua = [[Uimutableusernotificationaction alloc] init];
//2.setting notification behavior as text input
[UA Setbehavior:uiusernotificationactionbehaviortextinput];
//3.GiveActionGive a marker
[UA setidentifier:@ "myreply"];
//4.Set behavior activation mode to keep running in the background
[UA Setactivationmode:uiusernotificationactivationmodebackground];
when you set the activation mode here, if you reply in the notification bar/after reading you want to jump back to yourAPPthat should be the principle foreground activation mode if the reply/Select this mode when you want to keep the background running after reading
2.Set notification policy:
//1.Create a variable notification policy
uimutableusernotificationcategory * cate = [[Uimutableusernotificationcategory alloc] init];
//2.Givecategorya marker
[Cate setidentifier:@ "Textcategory"];
//3.for this strategycategorydevelop the relevant notification behaviorAction
[Cate Setactions:@[ua] forcontext:uiusernotificationactioncontextdefault];
3.Registration Notification Configuration(iOS8the way in the future):
//1.Create a user notification configuration through the policies above
uiusernotificationsettings * settings = [uiusernotificationsettings settingsfortypes: Uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound Categories:[nsset Setwitharray:@[cate]];
//2.register this notification configuration
[[UIApplication sharedapplication] registerusernotificationsettings:settings];
After these three parts, a custom notification policy is activated, and its notification behavior is entered and replied to as a text box.


Send local notifications



when you need to send a notification, you only need to set the corresponding policy and behavior, you can pop the notification in this way. With local notificationsuilocalnotificationFor example:
//1.initializing local notifications
uilocalnotification * Noti = [[Uilocalnotification alloc]init];
//2.set the notification body
[Noti setalertbody:[nsstring stringwithformat:@]you have a new message:%@ ", [NSDate new].description]];
//3.configure the corresponding policies and behaviors(must have been registered before.)
[Noti setcategory:@ "Textcategory"];
[Noti setalertaction:@ "myreply"];
//4.Pop-up notifications
[[UIApplication sharedapplication] presentlocalnotificationnow:noti];
Receive notification behavior text box reply content

since the new notification behavior is input, the current(As of this writing date2015.9Month)notifications are different for mainstream chat apps, such asQQin the notification bar, set theOKand cancel the button, this way though able to passOKButton Reply"OK"two words, but it can only be the two words. Reply message content is to write dead(hard WRITE)the.
and the new notification behavior is what the user enters in the notification bar to reply to what, soAPPyou need to get the content entered by the user.


below2auiapplicationdelegatethe proxy method provided by thisreplythe notification agent:
//Notification Agent with reply to local notifications
-(void) Application: (UIApplication *) application Handleactionwithidentifier: (Nullable NSString *) identifier Forlocalnotification: (uilocalnotification *) notification Withresponseinfo: (nsdictionary *) responseinfo Completionhandler: (void (^) ()) Completionhandler Ns_available_ios (9_0);
//Notification Agent with reply for remote notification
-(void) Application: (UIApplication *) application Handleactionwithidentifier: (Nullable NSString *) identifier Forremotenotification: (nsdictionary *) userInfo withresponseinfo: (nsdictionary *) Responseinfo Completionhandler: ( void (^) ()) Completionhandler Ns_available_ios (9_0);
regardless of local notifications and local notifications, get to the notification bar user input text content, just go toResponseinfoin this dictionary, takeUiusernotificationactionresponsetypedtextkeythisKeycorresponding to thestringjust fine.
or take local notifications as an example:
-(void) Application: (UIApplication *) application Handleactionwithidentifier: (Nullable NSString *) identifier Forlocalnotification: (uilocalnotification *) notification Withresponseinfo: (nsdictionary *) responseinfo Completionhandler: (void (^) ()) Completionhandler {
NSLog (@ "what the user enters in the text box:%@ ", Responseinfo [Uiusernotificationactionresponsetypedtextkey]);
Completionhandler ();
}

iOS9 development of New notice behavior

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.