1:ios local notifications and remote notifications
http://wangjun.easymorse.com/?p=1482
2: Apple remote Notification Service Request activation example (foreign Guy wrote.)
Http://mobiforge.com/developing/story/programming-apple-push-notification-services
3: Book reference: IPhone Development Cheats 16th Chapter push notifications.
Okay, get into the text:
The first is the URL for the certificate.
Https://developer.apple.com/ios/manage/overview/index.action
After the login is successful, go to the main page of iOS configuration management.
The first step is to create a new App when the IDs are created successfully, you will need to provide a security certificate to excite the push service, such as:
After selecting save to disk, generate a file name (CSR): certificatesigningrequest.certsigningrequest
Go back to the Apple page to submit this and prompt for excitement.
After the successful activation of the App IDs to download the development version or release of the active push Certificate (aps_development.cer), if you need to do a server proactive push, you have to download this file to use the push service.
The second step is to provide the app with a certificate to accept the push license, click Provisioning to set it up, add a new license, and select the app IDs that you just created. Then select the iphone device that you can debug.
Finally, the same is downloaded: ysypushmessagedemo.mobileprovision Double-click the certificate and let it load once.
Next, go to iOS Engineering and select Use this certificate to debug.
In the red circle, all the license certificates that were just loaded are set.
So here, the preparations for the certificate class are all ready.
Here again this emphasizes the specific role of each file
1:certificatesigningrequest.certsigningrequest: Used to generate app IDs
2:aps_development.cer certificates used to develop proactive push services
3:ysypushmessagedemo.mobileprovision License Service to accept push notifications for apps
For unsolicited push code and use, please refer to the first blog post at the beginning
This is only attached: Https://github.com/stefanhafeneger/PushMeBaby
Next, talk about receiving the push notification code aspect.
1: The app needs to accept the push message from the service provider,
[CSharp]View Plaincopy
- [[UIApplication Sharedapplication] registerforremotenotificationtypes: (Uiremotenotificationtypebadge | Uiremotenotificationtypesound | Uiremotenotificationtypealert)];
2: After the application is issued, if successful, the delegate will automatically return a device token (token), if it fails, it will enter another failed delegate
[CSharp]View Plaincopy
- Remote Notification Registration Successful delegation
- -(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken
- {
- NSLog (@"%@", Devicetoken);
- Self.viewController.toKenValueTextView.text = [NSString stringwithformat:@"%@", Devicetoken];
- Self.viewController.pushStatusLabel.text = @"already registered.";
- }
- Remote Notification registration failed delegation
- -(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error
- {
- Self.viewController.toKenValueTextView.text = [error description];
- }
3: Provide the device token code to the service provider for push to the specific phone. If a remote push message comes, the user taps the push message, or the app is already open, the system automatically calls the following delegate:
[CSharp]View Plaincopy
- Delegate that is called when a remote notification is clicked if the interface is open, the delegate responds directly to the
- -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo
- {
- NSLog (@"remote Notification");
- [Self pmd_uespushmessage:userinfo];
- }
4: The 3rd inside the situation is that the application is already running, the above delegate will be executed, if the application is not enabled, and then need to respond to the message, then the following delegate processing is required.
[CSharp]View Plaincopy
- - (BOOL) Application: (uiapplication *) application Didfinishlaunchingwithoptions: (nsdictionary *) launchoptions
- {
- //here processes the application if it is not started, but is opened by a notification message, you can get to the message at this time .
- if (launchoptions != nil) {
- nsdictionary * userinfo = [launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey];
- [self PMD_uesPushMessage:userInfo];
-     }  
- RETURN YES;  
- }  
5: Clear the Notification center of the existing push message, only need to set the specified app Badge to 0
[CSharp]View Plaincopy
- [[UIApplication sharedapplication] setapplicationiconbadgenumber:0];
6: The active push string must conform to the following JSON array format in order to correctly push to the phone.
@"{
//Custom Parameters
\ "Userinfo\":
{
\ "name\": \ "Remote Notice\"
},
//Standard notation
\ "Aps\":
{
\ "Alert\":
{
\ "action-loc-key\": \ "open\",//multi-lingual support
\ "body\": \ "Messgae content\"//Message body
},
\ "Badge\": 1,//For the app's icon tag specific values
\ "sound\": \ "default\" //playback of audio files, default means the system defaults to select the column ringtone
}
}";
It's almost over by here.
IOS Remote Push Notification detailed