iOS integrated friend League push

Source: Internet
Author: User

I've written about using Python to write a push server, and today, if you integrate the push service of the alliance

Before we do, we need to do some preparatory action.

#1. Register an app ID

#2. Enable push Notificationserivice, and create and download development/release Push certificates

#3. Install the push certificate and then push the certificate everywhere for the P12 file

#4. Pay attention to the Friend League account

#5. Create a push app and upload the P12 file for the push certificate and fill in the password

#6. Download the SDK to add to the project

In Appdelegatez

#import " UMessage.h "

Add a property

@property (nonatomic, strong) Nsdictionary *userinfo;

To add an agreement:

@interface Appdelegate () <UNUserNotificationCenterDelegate>

Set up Friends League Appkey

Static NSString *umessageappkey          @ "112345678901234523";

Create a method to configure the Allies push

- (void) Configureumessagewithlaunchoptions: (Nsdictionary *) launchoptions {//set Appkey & Launchoptions[Umessage Startwithappkey:umessageappkey launchoptions:launchoptions]; //Initialize[Umessage registerforremotenotifications]; //Turn on log[Umessage Setlogenabled:yes]; //Check for iOS 10 or later    if([[[[Uidevice Currentdevice] systemversion] Floatvalue] <10.0) {            } Else {                //If you have iOS 10 or later, you must do the following:Unusernotificationcenter *center =[Unusernotificationcenter Currentnotificationcenter]; Center.Delegate=Self ; Unauthorizationoptions Types10=Unauthorizationoptionbadge| Unauthorizationoptionalert |Unauthorizationoptionsound; [Center Requestauthorizationwithoptions:types10 Completionhandler:^ (BOOL Granted, Nserror *_nullable Error) {                                                                    if(granted) {//Click Allow//Here you can add some of your own logic                                                                        } Else {                                      //Click Not allowed//Here you can add some of your own logic                                                                        }    }]; }}

Protocol method:

- (void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {//turn off the pop-up box from the Friends League[Umessage Setautoalert:no];        [Umessage Didreceiveremotenotification:userinfo]; Self.userinfo=UserInfo; //Customizing the popup box    if([uiapplication Sharedapplication].applicationstate = =uiapplicationstateactive) {Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"Warm Tips"message:self.userinfo[@"APS"][@"Alert"]                                                           Delegate: Self cancelbuttontitle:@"Determine"Otherbuttontitles:nil];            [Alertview show]; }}//iOS10 NEW: Handling agent methods for receiving notifications from the foreground- (void) Usernotificationcenter: (Unusernotificationcenter *) Center willpresentnotification: (unnotification*) Notification Withcompletionhandler: (void(^) (unnotificationpresentationoptions)) completionhandler{nsdictionary* UserInfo =Notification.request.content.userInfo; if([Notification.request.trigger Iskindofclass:[unpushnotificationtriggerclass]]) {                //Remote push acceptance when the app is in the foreground//turn off the pop-up box from the Friends League[Umessage Setautoalert:no]; //This code must be added .[Umessage Didreceiveremotenotification:userinfo]; }Else{                //local push acceptance when the app is in the foreground    }        //when the app is in the foreground and prompts for settings, which one can be set whichCompletionhandler (Unnotificationpresentationoptionsound |Unnotificationpresentationoptionbadge|unnotificationpresentationoptionalert);}//iOS10 NEW: Proxy method for background click Notification-(void) Usernotificationcenter: (Unusernotificationcenter *) Centerdidreceivenotificationresponse: (Unnotificationresponse*) Response Withcompletionhandler: (void(^) ()) completionhandler{nsdictionary* UserInfo =Response.notification.request.content.userInfo; if([Response.notification.request.trigger Iskindofclass:[unpushnotificationtriggerclass]]) {                //Remote push acceptance when the app is in the background//This code must be added .[Umessage Didreceiveremotenotification:userinfo]; }Else{                //local push acceptance when the app is in the background    }}- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex {[Umessage sendclickreportforremotenotification:self. UserInfo];}

Finally, the method of configuring the AU push is called in Applicationdidfinishlaunch.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {         // Configure the friend Alliance push     [self configureumessagewithlaunchoptions:launchoptions];             return YES;}

iOS integrated friend League push

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.