One, local push
IOS push notification is divided into local push and remote push notification, remote push notification is similar to our usual use, even if the lock screen, you can also receive messages sent to us, and then on the home screen display a alertview, remote push requires remote server support, more complex. Local push is relatively simple and does not require support from the service side.
Local notifications are nslocalnotification implemented by instantiating a nslocalnotification type of notification, setting the Firedate property of the notification, the trigger time of the notification, and setting the TimeZone property, which is the time zone , set Alertbody, display content, set alertaction, set Soundname, that is, the sound when the push occurs, set the Applicationiconbadgenumber, the number on the icon, set the UserInfo property, This property is a variable of type nsdictionary. Then use the UIApplication instance method schedulelocalnotification: or Presentlocalnotificationnow: Push notification.
* 1. Create a local push *
//Create a local pushuilocalnotification*notification = [[[uilocalnotificationALLOC] init] autorelease];//Set after 10 secondsNSDate*pushdate = [NSDateDatewithtimeintervalsincenow:Ten];if(Notification! =Nil) {//Set push timeNotification. Firedate= Pushdate;//Push time zone settings: Search from the Internet //timezone is whether the uilocalnotification excitation time changes according to the time zone change, if set to nil, //Then the uilocalnotification will be fired at a later time, rather than an exact moment. Notification. TimeZone= [Nstimezone Defaulttimezone];//Set repeat interval, if not set will only push 1 timesNotification. Repeatinterval= Kcfcalendarunitday;//Push sound, (no sound when system pushes if not set)Notification. Soundname= Uilocalnotificationdefaultsoundname;//push content, (if not set, the text is not displayed in the push center, there is a sound prompt if the sound is set)Notification. Alertbody= @"Push content";//Push small icon settings, PS: This thing doesn't know what else to use .Notification. Alertlaunchimage=[[NSBundlemainbundle]pathforresource:@"3"oftype:@"JPG"];//The number of the red circle displayed on the iconNotification. Applicationiconbadgenumber=1;//Set UserInfo to be used after subsequent revocation nsdictionary*info = [nsdictionarydictionarywithobject:@"Name"forkey:@"Key"]; Notification. UserInfo= info;//Talk push settings and information join uiapplication* app=[uiapplicationSharedapplication];BOOLstatus=YES; for(uilocalnotification* Notification in App. Scheduledlocalnotifications) {if([Notification. UserInfoobjectforkey:@"Key"]) {status=NO; } }if(status) {//Join push (only once)[App Schedulelocalnotification:notification]; } }
* 2, receive local push *
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iWeibo" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; // 图标上的数字减1 application.applicationIconBadgeNumber1;
* 3. Remove Local push *
//Get uiapplicationuiapplication*app = [uiapplicationSharedapplication];//Get local push arrayNsarray*localarray = [App scheduledlocalnotifications];//Declare local notification objectuilocalnotification*localnotification;if(LocalArray) { for(uilocalnotification*noti in LocalArray) {nsdictionary*dict = Noti. UserInfo;if(dict) {NSString*inkey = [Dict objectforkey:@"Key"];if([Inkey isequaltostring:@"The corresponding key value"]) {if(localnotification) {[Localnotification release]; Localnotification =Nil; } localnotification = [Noti retain]; Break; } } }//Determine if a push is found for the same key that already exists if(!localnotification) {//There is no initializationLocalnotification = [[uilocalnotificationALLOC] init]; }if(localnotification) {//Do not push cancel push[App Cancellocalnotification:localnotification]; [Localnotification release];return; } }
Second, remote push
Read the reference link.
* Reference Link *
Local push
- http://my.oschina.net/CarlHuang/blog/139104
Remote push:
- http://blog.csdn.net/enuola/article/details/8627283
- Http://www.cnblogs.com/yh-qfnu/p/3269768.html
- Http://www.cocoachina.com/ios/20100401/900.html
- http://blog.csdn.net/dalehui/article/details/16807157
- Http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
- Http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2
- Http://mobiforge.com/design-development/programming-apple-push-notification-services
- http://segmentfault.com/a/1190000000520755
- Aurora Push Document
iOS messaging mechanism