Baidu Push (IOS)

Source: Internet
Author: User
1. First generate the Certificatesigningrequest file.

Click on Keychain Access--> request a certificate from a certification authority--> fill in the user email address--> common name--> Click Storage--> continue--> last click Save.

On the desktop can be seen Certificatesigningrequest.certsigningrequest file is a CSR file, we generate a CSR file at the same time, will be in the keychain access to generate a pair of secret keys, the name is just a common name we fill out.

2. Open Developer Center first create identifiers--> Create certificates--> in Create Provisoning Profiles

Note: 1. When creating identifiers, be sure to check the push notifications,

2. Ensure that the app ID in the name,provisoning profiles in the id,certificates in identifiers, bundle identifier in the application, is consistent.

3. Click on the keychain Access--> my certificate--> find the just generated. p12 file--> Click Export to the desktop.

4. Open the midrange-->openssl pkcs12-in push.p12-out push.pem-nodes and turn the. p12 file into a. pem file.

5. The steps to add to the SDK to the project are as follows:

Add libbpush.a and BPUSH.H to your own project, you need to be aware of the option to check the current target

6. Create and configure the Bpushconfig.plist file, create a new property list file in the project, name it bpushconfig.plist, and add the following key values:

?

1

2

3

4

5

{

"Production_mode" = NO

"Api_key" = "UZBMGZKHFUMVGYGOWCJSPFC1"

"DEBUG" = NO

}

Production_mode:

Must be selected. Apply Publishing mode. When you develop a certificate signature, the value is set to "NO", and the value is set to "YES" when the certificate signature is issued. Modify this value correctly when debugging and publishing applications so that push notifications cannot be reached.

Api_key:

Must be selected. The Baidu Developer Center automatically assigns API keys for each app that can be viewed in the Developer Center app profile.

6.SDK requires the following

Library: Foundation.framework, Coretelephony.framework, Libz.dylib, systemconfiguration.framework, please add in the project

7. Application:didfinishlaunchingwithoptions in Appdelegate: In the API, initialize the push:

Because there are changes to push in the iOS8, you have to judge the version of the device

1

2

[Bpush setupchannel:launchoptions];

[Bpush setdelegate:self]; Parameter objects must implement Onmethod:response: Method,














#if Support_ios8

8.0 Use this method to register push notifications later

if ([[[[[Uidevice Currentdevice] systemversion] floatvalue] >= 8.0) {

Uiusernotificationtype mytypes = Uiremotenotificationtypebadge | Uiremotenotificationtypealert | Uiremotenotificationtypesound;

Uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes:mytypes categories:nil];

[[UIApplication sharedapplication] registerusernotificationsettings:settings];

}else

#endif

{

Uiremotenotificationtype mytypes = uiremotenotificationtypebadge| Uiremotenotificationtypealert| Uiremotenotificationtypesound;

[[UIApplication sharedapplication] registerforremotenotificationtypes:mytypes];

}

8. In Application:didregisterforremotenotificationswithdevicetoken: Invoke API, register device token:

Bpush Registerdevicetoken:devicetoken]; Have to

[Bpush Bindchannel]; Have to. Can be invoked at other times, the app can receive a push message only if the method returns (via Onmethod:response: callback) Binding succeeds. One app binding succeeds at least once (if access token changes please rebind).

9. Implementation of the BPUSHDELEGATE protocol must be achieved by means of onmethod:response:











if ([Bpushrequestmethod_bind Isequaltostring:method])

{

nsdictionary* res = [[Nsdictionary alloc] initwithdictionary:data];

NSString *appid = [res valueforkey:bpushrequestappidkey];

NSString *userid = [res valueforkey:bpushrequestuseridkey];

NSString *channelid = [res valueforkey:bpushrequestchannelidkey];

int ReturnCode = [[res valueforkey:bpushrequesterrorcodekey] intvalue];

NSString *requestid = [res valueforkey:bpushrequestrequestidkey];

}


10. Invoke the API in Application:didreceiveremotenotification: To handle the received push message:

Gets the data returned after the push is sent


[Bpush Handlenotification:userinfo]; Optional

Related Article

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.