iOS local message push (uilocalnotification)

Source: Internet
Author: User

iOS local notification is managed centrally by iOS under Notificationmanager, simply by adding the encapsulated local notification objects to the system notification management mechanism queue. The system will fire the local notification at the specified time, and the application will complete the notification process simply by designing a method to handle notification.

iOS local notification has uilocalnotification object complete. It includes the following main attributes: Firedate, TimeZone, Repeatinterval, Repeatcalendar, Alertbody, Alertaction, Hasaction, Alertlaunchimage, Applicationiconbadgenumber, Soundname and UserInfo.

Dispatch of Uilocalnotification

firedate: Uilocalnotification the exact time of the excitation.

TimeZone: Determines whether the uilocalnotification excitation time changes according to the time zone change, if set to nil, then the uilocalnotification will be excited after a period of time, rather than a certain exact moment is excited.

Repeatinterval: Is the time difference between the uilocalnotification being repeated excitation, but the time difference is completely based on the calendar unit (nscalendarunit), such as the units fired per week, Nsweekcalendarunit, if not set, will not be fired repeatedly.

Repeatcalendar: Is the calendar that is used by the uilocalnotification to repeat the excitation, and if not set, the system default calendar will be used as the reference calendar.

soundname: Sets the sound when uilocalnotification messages are pushed, for example: Uilocalnotificationdefaultsoundname, or you can specify

Uilocalnotification's reminder content

alertbody, Alertaction, hasaction, Alertlaunchimage.

alertbody: Push content.

Applicationiconbadgenumber: The number of corner labels.

Setup UserInfo is convenient to use when you need to undo later

Nsdictionary *infodic = [nsdictionary dictionarywithobject:@ "name" forkey:@ "Key"];

Noti.userinfo = Infodic;

cancel a local push

UIApplication *app = [UIApplication sharedapplication];

Get local push array

Nsarray *localarr = [app scheduledlocalnotifications];

Declaring a local notification object

Uilocalnotification *localnoti;

if (Localarr) {

For (Uilocalnotification *noti in Localarr) {

Nsdictionary *dict = Noti.userinfo;

if (dict) {

NSString *inkey = [dict objectforkey:@ "key"];

if ([Inkey Isequaltostring:key]) {

if (Localnoti) {

[Localnoti release];

Localnoti = nil;

}

Localnoti = [Noti retain];

Break

}

}

}

Determine if a push is found for the same key that already exists

if (!localnoti) {

Initialization not present

Localnoti = [[Uilocalnotification alloc] init];

}

if (Localnoti &&!state) {

Do not push cancel push

[App Cancellocalnotification:localnoti];

[Localnoti release];

Return

}

}

4. Two ways to unregister a local notification, one is to cancel the specified notification, and the second is to cancel all registration notices:

[[UIApplication sharedapplication] cancellocalnotification:localnotification];

[[UIApplication sharedapplication] cancelalllocalnotification];

iOS local message push (uilocalnotification)

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.