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