iOS_极光推送
2016-06-09 00:25
453 查看
1、在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
调用自定义的方法,使用极光推送
[self
registerPushNotificationWithlaunchOptions:launchOptions];
2.1、向apple服务器注册通知服务
2.2、初始化JPUSH参数
3、
将deviceToken上传到第3方服务器 和 自己的服务器
/**
* @programmer shuaixiao
* @brief 将deviceToken上传到服务器
* @param <#无#>
* @return <#无#>
*/
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
/// Required - 注册 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
//----- register result -----
//uid: 4949826728
//registrationID:171976fa8a80077f0b3
}
4、处理接收到的消息
/**
* @programmer shuaixiao
* @brief 前台、后台、退出时均可收到消息
* @param <#无#>
* @return <#无#>
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
kLogAndShowMessage(@"来消息了")
[self handleWithNotificationDict:userInfo];
// IOS 7 Support Required
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
5、跳转代码
- (void)handleWithNotificationDict:(NSDictionary *)userInfo
{
// 写跳转代码即可
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UILabel *label = [[UILabel alloc]initWithFrame:keyWindow.frame];
label.text = [userInfo description];
label.numberOfLines = 0;
label.alpha = 0.8;
label.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
[keyWindow addSubview:label];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
调用自定义的方法,使用极光推送
[self
registerPushNotificationWithlaunchOptions:launchOptions];
- (void)registerPushNotificationWithlaunchOptions:(NSDictionary *)launchOptions { // 向apple服务器注册通知服务 [self registerForRemoteNotification]; // 初始化JPUSH参数 [self setupJPUSHWithOption:launchOptions]; }
2.1、向apple服务器注册通知服务
/** * @programmer shuaixiao * @brief 向apple服务器注册通知服务 * @param <#无#> * @return <#无#> */ - (void)registerForRemoteNotification { //Required if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { //可以添加自定义categories [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; } else { //categories 必须为nil [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil]; } }
2.2、初始化JPUSH参数
/** * @programmer shuaixiao * @brief 初始化JPUSH参数 * @param <#无#> * @return <#无#> */ - (void)setupJPUSHWithOption:(NSDictionary *)launchOptions { //Required // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。 NSString *configPath = [[NSBundle mainBundle]pathForResource:@"PushConfig.plist" ofType:nil]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:configPath]; NSString *appKey = [dict objectForKey:@"APP_KEY"]; NSString *channel = [dict objectForKey:@"CHANNEL"]; NSString *isProduction = [dict objectForKey:@"APS_FOR_PRODUCTION"]; [JPUSHService setupWithOption:launchOptions appKey:appKey channel:channel apsForProduction:isProduction advertisingIdentifier:nil]; }
3、
将deviceToken上传到第3方服务器 和 自己的服务器
/**
* @programmer shuaixiao
* @brief 将deviceToken上传到服务器
* @param <#无#>
* @return <#无#>
*/
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
/// Required - 注册 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
//----- register result -----
//uid: 4949826728
//registrationID:171976fa8a80077f0b3
}
4、处理接收到的消息
/**
* @programmer shuaixiao
* @brief 前台、后台、退出时均可收到消息
* @param <#无#>
* @return <#无#>
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
kLogAndShowMessage(@"来消息了")
[self handleWithNotificationDict:userInfo];
// IOS 7 Support Required
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
5、跳转代码
- (void)handleWithNotificationDict:(NSDictionary *)userInfo
{
// 写跳转代码即可
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UILabel *label = [[UILabel alloc]initWithFrame:keyWindow.frame];
label.text = [userInfo description];
label.numberOfLines = 0;
label.alpha = 0.8;
label.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
[keyWindow addSubview:label];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?