日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS 注册极光推送

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS 注册极光推送 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注冊極光推送


一.在 AppDelegate.h 文件中定義appKeychannelisProduction三個字段

#import <UIKit/UIKit.h>


static NSString *appKey = @"XXXXXXXXXX";

static NSString *channel = @"Publish channel";

static BOOL isProduction = FALSE;


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


二.在 AppDelegate.m 文件中添加 極光推送的頭文件 和 iOS 10.0 以上系統版本的 <UserNotifications/UserNotifications.h>

#import "JPUSHService.h"

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

#import <UserNotifications/UserNotifications.h>

#endif


三.添加代理方法

@interface AppDelegate ()<UNUserNotificationCenterDelegate,JPUSHRegisterDelegate>


四.注冊極光推送

- (void)registJPushWithlaunchOptions:(NSDictionary *)launchOptions{

?? ?

? ? //3.0.0以前版本舊的注冊方式

? ? if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {

#ifdef NSFoundationVersionNumber_iOS_9_x_Max

? ? ? ? JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];

? ? ? ? entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;

? ? ? ? [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];

#endif

? ? } else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

? ? ? ? //可以添加自定義categories

? ? ? ? [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UIUserNotificationTypeSound |

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UIUserNotificationTypeAlert)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? categories:nil];

? ? }

?? ?

? ? //如不需要使用IDFAadvertisingIdentifier 可為nil

? ? [JPUSHService setupWithOption:launchOptions appKey:appKey

? ? ? ? ? ? ? ? ? ? ? ? ? channel:channel

?? ? ? ? ? ? ? ? apsForProduction:isProduction

? ? ? ? ? ? advertisingIdentifier:nil];

?? ?

? ? //2.1.9版本新增獲取registration id block接口。

? ? [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {

? ? ? ? if(resCode == 0){

//? ? ? ? ? ? NSLog(@"registrationID獲取成功:%@",registrationID);

?? ? ? ? ? ?

? ? ? ? }

? ? ? ? else{

//? ? ? ? ? ? NSLog(@"registrationID獲取失敗,code%d",resCode);

? ? ? ? }

? ? }];

?? ?

}


//注冊成功,獲取deviceToken

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

?? ?

//? ? NSLog(@"%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);

? ? [JPUSHService registerDeviceToken:deviceToken];

}


- (void)application:(UIApplication *)application

didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

//? ? NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);

}


#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

- (void)application:(UIApplication *)application

didRegisterUserNotificationSettings:

(UIUserNotificationSettings *)notificationSettings {

}


- (void)application:(UIApplication *)application

handleActionWithIdentifier:(NSString *)identifier

forRemoteNotification:(NSDictionary *)userInfo

? completionHandler:(void (^)())completionHandler {

}

#endif


+ (void)registrationIDCompletionHandler:(void(^)(int resCode,NSString *registrationID))completionHandler{

?? ?

}


總結

以上是生活随笔為你收集整理的iOS 注册极光推送的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。