[Reprint]ios local Push-spare

Source: Internet
Author: User

First step: Create a local push
Create a local push
Uilocalnotification *notification = [[[[Uilocalnotification alloc] init] autorelease];
Set after 10 seconds
NSDate *pushdate = [NSDate datewithtimeintervalsincenow:10];
if (notification! = nil) {
Set push time
Notification.firedate = pushdate;
Setting the time zone
Notification.timezone = [Nstimezone defaulttimezone];
Set the recurrence interval
Notification.repeatinterval = Kcfcalendarunitday;
Push Sound
Notification.soundname = Uilocalnotificationdefaultsoundname;
Push content
Notification.alertbody = @ "Push content";
The number of the red circle displayed on the icon
Notification.applicationiconbadgenumber = 1;
Setup UserInfo is convenient to use when you need to undo later
Nsdictionary *info = [nsdictionary dictionarywithobject:@ "name" forkey:@ "Key"];
Notification.userinfo = info;
Add push to UIApplication
UIApplication *app = [UIApplication sharedapplication];
[App Schedulelocalnotification:notification];

}

Step two: Receive local push
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification*) notification{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "IWeibo" Message:notification.alertBody Delegate:nil cancelbuttontitle:@ "determine" otherbuttontitles:nil];
[Alert show];
The number on the icon minus 1
Application.applicationiconbadgenumber-= 1;
}

Step three: Unblock local push
Get UIApplication
UIApplication *app = [UIApplication sharedapplication];
Get local push array
Nsarray *localarray = [app scheduledlocalnotifications];
Declaring a local notification object
Uilocalnotification *localnotification;
if (LocalArray) {
For (Uilocalnotification *noti in LocalArray) {
Nsdictionary *dict = Noti.userinfo;
if (dict) {
NSString *inkey = [dict objectforkey:@ "key"];
if ([Inkey isequaltostring:@ "corresponding key value"]) {
if (localnotification) {
[Localnotification release];
Localnotification = nil;
}
Localnotification = [Noti retain];
Break
}
}
}

Determine if a push is found for the same key that already exists
if (!localnotification) {
Initialization not present
Localnotification = [[Uilocalnotification alloc] init];
}

if (localnotification) {
Do not push cancel push
[App Cancellocalnotification:localnotification];
[Localnotification release];
Return
}
}

[Reprint]ios local Push-spare

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.