IOS Study Notes 45-local notification uilocalnotification

Source: Internet
Author: User

There are two types of message push methods in iOS, one is remote server push (apns). I have mentioned apns: publish in my previous notes.

Uilocalnotification * notification = [[uilocalnotification alloc] init]; nsdateformatter * formatter = [[nsdateformatter alloc] init]; [formatter setdateformat: @ "HH: mm: SS"]; // The time when the notification is triggered nsdate * Now = [formatter datefromstring: @ "15:00:00"]; notification. firedate = now; // Time Zone Notification. timezone = [nstimezone defaulttimezone]; // The unit of the duplicate notification, which can be day, week, or month notification. repeatinterval = nsdaycalendarunit; // notification content notification. alertbody = @ "this is a new notification"; // notification of the sound played when the notification is triggered. soundname = uilocalnotificationdefaultsoundname; // execute the notification registration [[uiapplication sharedapplication] schedulelocalnotification: Notification];

The above code implements such a scenario: Some todo and alarm clock applications have the function of notifying users, using the local notification uilocalnotification in iOS, some applications will prompt users to return to the application at a fixed time every day, every week, or every month, and also use local notifications. The above code snippet will bring up a notification prompt at three o'clock P.M. every day.

To include parameter information in the notification, use the following method:

NSDictionary *dic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];    notification.userInfo = dic;

If the software is running, you can use the callback method in appdelegate to obtain and process the parameter information:

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{    if (notification) {        NSDictionary *userInfo =  notification.userInfo;        NSString *obj = [userInfo objectForKey:@"key"];        NSLog(@"%@",obj);    }}

In addition, you can cancel the registration of local notifications in two ways, one is to cancel the specified notification, and the other is to cancel all registration notifications:

[[UIApplication sharedApplication] cancelLocalNotification:localNotification];   [[UIApplication sharedApplication] cancelAllLocalNotification];

The above briefly introduces the use of uilocalnotification. You are welcome to correct and add it!

To join our QQ group or public account, see: Ryan's
Zone public account and QQ Group

At the same time, you are welcome to follow my Sina Weibo chat with me: @ Tang Ren _ Ryan

Related Article

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.