iOS messaging mechanism

Source: Internet
Author: User

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

    1. http://my.oschina.net/CarlHuang/blog/139104

Remote push:

    1. http://blog.csdn.net/enuola/article/details/8627283
    2. Http://www.cnblogs.com/yh-qfnu/p/3269768.html
    3. Http://www.cocoachina.com/ios/20100401/900.html
    4. http://blog.csdn.net/dalehui/article/details/16807157
    5. Http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
    6. Http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2
    7. Http://mobiforge.com/design-development/programming-apple-push-notification-services
    8. http://segmentfault.com/a/1190000000520755
    9. Aurora Push Document

iOS messaging mechanism

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.