IOS极光推送流程

首先肯定要先去极光进行最基本的注册,注册完在商品应用管理找到对应的 应用点击进去,点击iOS 把生产证书还有开发证书导入进去。(证书在苹果开发者中心获取

IOS极光推送流程_第1张图片
然后再自己工程中配置相关文件,首先倒入极光的SDK,我用的是3.0.2的SDK,去官网下载
IOS极光推送流程_第2张图片

接下来在Build Phases倒入相关文件库

CFNetwork.framework

CoreFoundation.framework

CoreTelephony.framework

SystemConfiguration.framework

CoreGraphics.framework

Foundation.framework

UIKit.framework

Security.framework

libz.tbd (Xcode7以下版本是libz.dylib)

AdSupport.framework (获取IDFA需要;如果不使用IDFA,请不要添加)

UserNotifications.framework (Xcode8及以上)

libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)

然后再工程里设置

IOS极光推送流程_第3张图片
然后再Appdelegate里边进行设置
IOS极光推送流程_第4张图片
IOS极光推送流程_第5张图片
下边继续 因为太长就没截图,直接上代码

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

/// Required - 注册 DeviceToken

[JPUSHService registerDeviceToken:deviceToken];

}

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

//Optional

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

}

#pragma mark- JPUSHRegisterDelegate

// iOS 10 Support

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {

// Required

NSDictionary * userInfo = notification.request.content.userInfo;

if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {

[JPUSHService handleRemoteNotification:userInfo];

}

completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置

}

// iOS 10 Support

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

// Required

NSDictionary * userInfo = response.notification.request.content.userInfo;

if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {

[JPUSHService handleRemoteNotification:userInfo];

}

completionHandler();  // 系统要求执行这个方法

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

// Required, iOS 7 Support

[JPUSHService handleRemoteNotification:userInfo];

completionHandler(UIBackgroundFetchResultNewData);

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

// Required,For systems with less than or equal to iOS6

[JPUSHService handleRemoteNotification:userInfo];

}

这样就完成了一个推送功能啦!!!其实 官方文档还是挺全面的,看不懂的可以参照官方文档看一下

你可能感兴趣的:(IOS极光推送流程)