iOS Local notifications

Source: Internet
Author: User

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

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.