IOS-Baidu Push

Source: Internet
Author: User

In many project development, everyone has done push! For example: Aurora push, homing pigeon push, push and so on a series of push. We are using the Integrated SDK, and the principle is the same.
Here we do a bit Baidu push to send.

1. Baidu Push 1.1 Baidu Account registration application and audit

Login Baidu Cloud push: HTTP://PUSH.BAIDU.COM/FC. Fill in the relevant information, audit.
After the approval to download the SDK, create the application (upload the appropriate push certificate format to see requirements to out), the default creation of the application is, developer testing, on-line to be converted to production.

1.2 SDK Import and configuration

1) The SDK used is simple. (There is a test audio TEXT.CAF)

2) whether the corresponding library is imported

3) certificate with push function

The use of the 1.3 SDK in the project

1) Write at startup

- *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{//***********************关于如何设置badge角标加1的方法***********************/* 服务端推送的badge是几就会显示几,你只需要跟服务端同步消息数目,然后让服务端自己,该推送几,就推送几,比如你应用打开的时候,或者进入后台的时候跟服务端同步,这个点,需要你们自己去设计,应用没有消息的时候,服务端推送了1,当应用打开时候,告诉服务端,app没点击通知,那下次应用推送2,依次类推。 */
    //IOS8 need to use the new API    if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=8.0) {Uiusernotificationtype Mytypes = Uiusernotificationtypebadge | Uiusernotificationtypesound |        Uiusernotificationtypealert; Uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes:mytypes categories:Nil]; [[uiapplicationSharedapplication] registerusernotificationsettings:settings]; }Else{Uiremotenotificationtype Mytypes = uiremotenotificationtypebadge| Uiremotenotificationtypealert|        Uiremotenotificationtypesound; [[uiapplicationSharedapplication] registerforremotenotificationtypes:mytypes]; }#warning test the development environment, you need to modify the Bpushmode for Bpushmodedevelopment to modify apikey for your own apikey    //Register Baidu Cloud push service when APP launches, need to provide Apikey[Bpush registerchannel:launchoptions apikey:@"Apikey changed to his own."Pushmode:bpushmodedevelopment withfirstaction:NilWithsecondaction:NilWithcategory:NilIsdebug:YES];//APP is user Click Push Message to start    nsdictionary*userinfo = [Launchoptions Objectforkey:uiapplicationlaunchoptionsremotenotificationkey];if(UserInfo) {NSLog(@"Start from Message:%@", UserInfo);    [Bpush Handlenotification:userinfo]; }//Corner SD 0[[uiapplicationSharedapplication] Setapplicationiconbadgenumber:0];}

2) Click Push Message

//This method is the user clicks the notice, applies in the foreground or the background and applies in the Backstage Si cho- (void) Application: (uiapplication*) Application Didreceiveremotenotification: (nsdictionary*) UserInfo Fetchcompletionhandler: (void(^) (Uibackgroundfetchresult)) completionhandler{Completionhandler (Uibackgroundfetchresultnewdata);NSLog(@"********** iOS7.0 after background **********");//application in the foreground or background open state, do not jump page, let users choose.     if(Application. ApplicationState= = Uiapplicationstateactive | | Application. ApplicationState= = Uiapplicationstatebackground) {NSLog(@"acitve or Background"); Uialertview *alertview =[[uialertview alloc]initwithtitle:@"Receive a message"message:userinfo[@"APS"][@"Alert"] Delegate: Selfcancelbuttontitle:@"Cancel"otherbuttontitles:@"OK",Nil];    [Alertview show]; }Else//Kill status, jump directly to the jump page. {//Here to implement page jump}}

3) Registration of push service

//In the IOS8 system, you also need to add this method. Registering a push service with the new API- (void) Application: (uiapplication*) Application didregisterusernotificationsettings: (uiusernotificationsettings *) notificationsettings{[ Application registerforremotenotifications];} - (void) Application: (uiapplication*) Application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken{NSLog(@"test:%@", Devicetoken);    [Bpush Registerdevicetoken:devicetoken]; [Bpush bindchannelwithcompletehandler:^ (IDResultNserror*error) {//need to Settag Listtag Deletetag unbind operation after the binding succeeds or it will fail        if(Result) {[Bpush settag:@"MyTag"withcompletehandler:^ (IDResultNserror*error) {if(Result) {NSLog(@"Set tag Success");        }            }]; }    }];}//When Devicetoken gets failed, the system will callback this method- (void) Application: (uiapplication*) Application Didfailtoregisterforremotenotificationswitherror: (Nserror*) error{NSLog(@"Devicetoken get failed, Reason:%@", error);}

4) When a push message is received

- (void) Application: (uiapplication*) Application Didreceiveremotenotification: (nsdictionary*) userinfo{//APP receives push notifications[Bpush Handlenotification:userinfo];NSLog(@"********** ios7.0 before **********");//application in the foreground or background open state, do not jump page, let users choose.     if(Application. ApplicationState= = Uiapplicationstateactive | | Application. ApplicationState= = Uiapplicationstatebackground) {NSLog(@"acitve or Background"); Uialertview *alertview =[[uialertview alloc]initwithtitle:@"Receive a message"message:userinfo[@"APS"][@"Alert"] Delegate: Selfcancelbuttontitle:@"Cancel"otherbuttontitles:@"OK",Nil];    [Alertview show]; }Else//Kill status, jump directly to the jump page. {    }}- (void) Application: (uiapplication*) Application Didreceivelocalnotification: (uilocalnotification*) notification{NSLog(@"Receive local notifications!!!" "); [Bpush showlocalnotificationatfront:notification Identifierkey:Nil];}
1.4 Turn push button on and off

Tell me about my thoughts and practices: Save a parameter 1 or 0 locally, for example: status is used to store the state. Add a button, click the Off state status to store 0, while the Uiusernotificationtype is set to: Uiusernotificationtypenone Uiremotenotificationtype set to: Uiremotenotificationtypenone back to sound, badges, pop-up reminders.
Other jump pages and other operations can be pre-sentenced to the state status.

Other specific content of each push has its own specific detailed documents, explained more than I write more detailed, if there is anything wrong do not know where to comment, I will promptly answer and modify!

IOS-Baidu 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.