Detailed Explanation of IOS Remote Notification Compatibility (IOS7 IOS8) Examples
- 2021-12-12 06:02:03
- OfStack
IOS Remote Notification
1. Certificate push installation
I won't say the operation process of certificates. There are a lot of certificates on the Internet. First of all, I want to say why these certificates are actually telling Apple Server 3 points:
1. Which app do we push for
2. Which computer do push debugging
3. Which mobile phone device does push debugging
I highlight debugging because people always ask why I want to double-click on mac to install cer files and mobileprovision files, just because you want to debug, if you don't debug you can build and not install.
2. Code implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if (IS_iOS_8) {
// Gets the current UIUserNotificationType Status
UIUserNotificationType oType = application.currentUserNotificationSettings.types;
if (oType == UIUserNotificationTypeNone) {
NSLog(@" Notification is prohibited ");
}else{
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
}else{
UIRemoteNotificationType type = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:type];
}
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
// The Apple server told us the device number
NSLog(@"%@,%@",NSStringFromSelector(_cmd),deviceToken);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
// Notifications pushed to us by our company server
NSLog(@"%@",userInfo);
}
Thank you for reading, hope to help everyone, thank you for your support to this site!