簡單生成推送證書

點擊下載的兩張證書(激活操作),然後在鑰匙串中,分別選中並導出.c12文件,保存在本地,就可以用這兩張證書( Apple Development IOS Push Services是調試證書,Apple Push Services : 是發佈證書)。

以上證書配置完成後,就可以在appdelegate.m中配置對應的推送內容了:

- (void)registerAPNS
{
    //APNS 註冊
#ifdef __IPHONE_8_0
    //Right, that is the point
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                         |UIRemoteNotificationTypeSound
                                                                                         |UIRemoteNotificationTypeAlert) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#else
    //register to receive notifications
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif
    
}
#pragma mark APPLE APNS

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
    if (notificationSettings.types!=UIUserNotificationTypeNone) {
        setIsLocalNotification(@YES);
    }else {
        setIsLocalNotification(@NO);
    }
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
    //handle the actions
    if ([identifier isEqualToString:@"declineAction"]){
    }
    else if ([identifier isEqualToString:@"answerAction"]){
    }
}
#endif

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    // 接受apple 推送消息  可以自定義顯示
//    NSString *message = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
//    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
//                                                        message:message
//                                                       delegate:self
//                                              cancelButtonTitle:@"取消"
//                                              otherButtonTitles:@"確定", nil];
//    [alertView show];
}
<pre name="code" class="objc">- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken
{//獲取設備號,並要後臺提供一個接口,用於將用戶token和設備號進行綁定
               [[APIClient shareInstance] registerPhonePushMessageBy:getUserToken</span>
                                                   AppleToken:deviceToken
                                                      Success:^(NSString *successMsg)
                                                             {
                                                                 
                                                             }
                                                      Failure:^(NSString *faileMessage)
                                                             {
                                                             }];
    
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error
{
    
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章