Send notification:
Uilocalnotification *newnotification = [[Uilocalnotification alloc] init];
if (newnotification) {
Time
Newnotification.timezone=[nstimezone Defaulttimezone];
Push Event---10 seconds later
Newnotification.firedate=[[nsdate Date] datebyaddingtimeinterval:10];
Push content
Newnotification.alertbody = @ "Signal alarm";
Apply red icon number in top right corner
Newnotification.applicationiconbadgenumber = 1;
Note:
1: format sure to support playback, common format CAF
2: Audio playback time cannot be greater than 30 seconds
3: In the resource to find the audio file, pour the best can point the project name right-click Add Import
Newnotification.soundname = @ "JINGBAO2.CAF";
Set button
Newnotification.alertaction = @ "Off";
Judging repetition or not
Newnotification.repeatinterval = Nsweekcalendarunit;
A dictionary that is stored, used to pass data, to distinguish multiple notifications
Nsmutabledictionary *dicuserinfo = [[Nsmutabledictionary alloc] init];
[Dicuserinfo setvalue:@ "" forkey:@ "Clockid"];
float Floatheng = userLocation.location.coordinate.latitude;
float Floatshu = userLocation.location.coordinate.longitude;
[Dicuserinfo setvalue:[nsstring stringwithformat:@ "%f", Strx] forkey:@ "Heng"];
[Dicuserinfo setvalue:[nsstring stringwithformat:@ "%f", Stry] forkey:@ "Shu"];
Newnotification.userinfo = [nsdictionary dictionarywithobject:dicuserinfo forkey:@ "dictionary"];
[Dicuserinfo release];
[[UIApplication sharedapplication] schedulelocalnotification:newnotification];
}
NSLog (@ "Post new localnotification:%@", newnotification);
[Newnotification release];
[Pool release];
To cancel a notification:
Be sure to cancel when the notification is complete, iOS allows up to 64 recent local notifications, and local notifications exceeding the limit will be ignored.
1: Remove all notifications from app
[[UIApplication sharedapplication] cancelalllocalnotifications];
2: Delete Individual notifications according to the dictionary
Key: The dictionary value passed in when the notification is sent to determine which push
for (int i=0; I<[myarray count]; i++) {
Uilocalnotification *myuilocalnotification=[myarray OBJECTATINDEX:I];
if ([[[[Myuilocalnotification UserInfo] objectforkey:@ "key"] intvalue][email protected] "dictionary value") {
[[UIApplication sharedapplication] cancellocalnotification:myuilocalnotification];
}
}
Notifies the method that the call was executed APPDELEGATE.M class inside
Push-through of executed events
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{
Notification is the dictionary information that is passed in when the notification is sent
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "title" Message:notification.alertBody Delegate:nil cancelbuttontitle:@ "determine" otherbuttontitles:nil];
[Alert show];
[Alert release];
}
Finally, there's another place: execution notifications Be sure to exit the app before you get notified.
iOS Local notifications