IOS Local Notifications

Source: Internet
Author: User

In the iOS8 system, adding this sentence is to allow users to send local notifications

-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {

if ([uiapplication instancesrespondtoselector:@selector( Registerusernotificationsettings:)]) {

        [application  registerusernotificationsettings: Uiusernotificationtypealert| Uiusernotificationtypebadge| Uiusernotificationtypesound categories: nil

}

//Override point for customization after application launch.

return YES;

}

Cancel Notification

-(void) Application: (uiapplication *) application didreceivelocalnotification: ( Uilocalnotification *) notification

{

NSString *pathstring = [[NSBundle mainbundle] pathforresource:@ " tick - regaling " oftype:@ "MP3"];

Avaudioplayer *avaudio = [[Avaudioplayer alloc] Initwithcontentsofurl:[[nsurl alloc] initfileurlwithpath:pathstring ] Error:nil];

Avaudio.delegate = self;

[Avaudio play];

application. Applicationiconbadgenumber = 0;

//[Avaudio release];

}

Register a notification

uilocalnotification *notification=[[uilocalnotification alloc]init];

if (notification!=Nil)

{

nsdate *now = [nsdate date];

// from now on, notify after ten seconds

Notification. firedate=[now datebyaddingtimeinterval: 50];

// use local time zone

notification. TimeZone=[nstimezone defaulttimezone];

// notification of repeated prompt units, which can be days, weeks, months

Notification.repeatinterval = Nscalendarunitcalendar;

Notification. alertbody=@ "1111";


// notification tones use the default

notification. Soundname=uilocalnotificationdefaultsoundname;

            notification.alertaction =@ " you 1111 Span style= "Line-height:27px;color:rgb (180,38,26);" > ",  

// This notification to the time when you display the number in the upper right corner of your application.

Notification. Applicationiconbadgenumber = 1;

add Key  this key

          

*dict =[ nsdictionary Dictionarywithobjectsandkeys @ "MM" @ "Nfkey" nil

[Notification Setuserinfo:d ICT];

// Start this notification

[[uiapplication sharedapplication] schedulelocalnotification: notification];

}


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1754488

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.