(73) Implementation of iOS local push notifications

Source: Internet
Author: User

iOS push notifications are divided into local push and network push two, if the app is suspended, can send local notifications, if it has been killed, then only the timing notification can be executed, and similar to the kind of QQ network message push will not be implemented, because the app's network module is not executed after being killed, This is the time to use remote notification, through the Apple server forwarding notifications to the phone, this article only describes the use of local notifications.

① for iOS8 and above, you need to register for local notification to use, generally registered in Appdelegate:

if ([[Uidevice currentdevice].systemversion Doublevalue] >= 8.0) {        uiusernotificationsettings *settings = [ Uiusernotificationsettings Settingsfortypes:uiusernotificationtypealert | Uiusernotificationtypesound Categories:nil];        [Application registerusernotificationsettings:settings];}

Where Settingsfortypes is a series of parameters can be tied, the realization principle is that multiple bits represent multiple functions, each function in a different bit, when each phase or, the corresponding bit is set 1, thereby opening the function, here is alert notification and voice prompts. Categories is a nsset, the official explanation is to inform the inclusion of a series of acts, generally write nil can.

② send a notification, need to set Alertbody (message body), firedate (send time), Soundname (beep, General fill default).

Finally, the Schedulelocalnotification method is used to send the notification using the UIApplication single instance call:

Uilocalnotification *localnoti = [[Uilocalnotification alloc] init];localnoti.alertbody = [NSString stringWithFormat:@ "%@:%@", message.fromstr,message.body];localnoti.firedate = [NSDate date];localnoti.soundname = @ "Default"; [[UIApplication sharedapplication] schedulelocalnotification:localnoti];
General notifications are sent only when the app is in the background, so it should be judged before sending, judging by the following:

[uiapplication sharedapplication].applicationstate! = uiapplicationstateactive



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

(73) Implementation of iOS local push notifications

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.