1、导入框架

2、

//推送

#import "APService.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

// Required J push功能

//1注册极光

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

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

//可以添加自定义categories

[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

UIUserNotificationTypeSound |

UIUserNotificationTypeAlert)

categories:nil];

} else {

//categories 必须为nil

[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)

categories:nil];

}

#else

//categories 必须为nil

[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)

categories:nil];

#endif

// Required

[APService setupWithOption:launchOptions];

return YES;

}

#pragma mark- J push

- (void)applicationWillEnterForeground:(UIApplication *)application {

[application setApplicationIconBadgeNumber:0];

[application cancelAllLocalNotifications];

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the

// application was inactive. If the application was previously in the

// background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if

// appropriate. See also applicationDidEnterBackground:.

}

- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

//    rootViewController.deviceTokenValueLabel.text =

//    [NSString stringWithFormat:@"%@", deviceToken];

//    rootViewController.deviceTokenValueLabel.textColor =

//    [UIColor colorWithRed:0.0 / 255

//                    green:122.0 / 255

//                     blue:255.0 / 255

//                    alpha:1];

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

[APService registerDeviceToken:deviceToken];

//注册成功以后给自己服务器的registrationID

_registrationID=[NSString stringWithFormat:@"%@",  [APService registrationID]];

}

- (void)application:(UIApplication *)application

didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

DLog(@"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 {

}

// Called when your app has been activated by the user selecting an action from

// a local notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication *)application

handleActionWithIdentifier:(NSString *)identifier

forLocalNotification:(UILocalNotification *)notification

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

}

// Called when your app has been activated by the user selecting an action from

// a remote notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication *)application

handleActionWithIdentifier:(NSString *)identifier

forRemoteNotification:(NSDictionary *)userInfo

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

}

#endif

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo {

[APService handleRemoteNotification:userInfo];

NSLog(@"收到通知:%@", [self logDic:userInfo]);

//    [rootViewController addNotificationCount];

}

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

fetchCompletionHandler:

(void (^)(UIBackgroundFetchResult))completionHandler {

[APService handleRemoteNotification:userInfo];

NSLog(@"收到通知:%@", [self logDic:userInfo]);

//    [rootViewController addNotificationCount];

completionHandler(UIBackgroundFetchResultNewData);

}

- (void)application:(UIApplication *)application

didReceiveLocalNotification:(UILocalNotification *)notification {

[APService showLocalNotificationAtFront:notification identifierKey:nil];

}

// log NSSet with UTF8

// if not ,log will be \Uxxx

- (NSString *)logDic:(NSDictionary *)dic {

if (![dic count]) {

return nil;

}

NSString *tempStr1 =

[[dic description] stringByReplacingOccurrencesOfString:@"\\u"

withString:@"\\U"];

NSString *tempStr2 =

[tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

NSString *tempStr3 =

[[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];

NSString *str =

[NSPropertyListSerialization propertyListFromData:tempData

mutabilityOption:NSPropertyListImmutable

format:NULL

errorDescription:NULL];

return str;

}

- (void)applicationWillResignActive:(UIApplication *)application

{

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application

{

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

}

极光推送Jpush功能(具体参照官网说明文档,注意此文红色字体)的更多相关文章

  1. 关于极光推送Jpush的demo

    关于极光推送Jpush 推送是手机app必不可少的一样功能,这次由于公司项目需要研究了一下.由于推送一般写于服务端,所以对于不会Android的javaweb程序员要写出一个完整的demo是一件很头痛 ...

  2. 1、Android Studio集成极光推送(Jpush) 报错 java.lang.UnsatisfiedLinkError: cn.jpush.android.service.PushProtoco

    Android studio 集成极光推送(Jpush) (华为手机)报错, E/JPush: [JPushGlobal] Get sdk version fail![获取sdk版本失败!] W/Sy ...

  3. 李洪强iOS开发之极光推送JPush

    李洪强iOS开发之极光推送JPush

  4. 极光推送JPush的快速集成

    首先到极光推送的官网上创建一个应用,填写对应的应用名和包名. 创建好之后下载Demo 提取Sdk里面的图片和xml等资源文件放自己项目的相应位置,然后要注意的是.so文件的放置位置: 在main目录下 ...

  5. 极光推送(JPush)开篇

    Date:2019-11-11 读前思考: 极光推送是什么? 极光推送是能做什么?有什么优势? 怎么根据业务需求来实现极光推送服务呢? 简介 极光推送(JPush)是独立的第三方云推送平台,致力于为全 ...

  6. 极光推送Jpush(v3)服务端PHP版本集成(V3版本只调用推送API)

    因为版本升级,极光推送的API也有了V3,功能也更丰富了,但是对于我们有的用户来说,我们还是只需要调用推送的API就够了. 下载了一份PHP服务端的SDK(下载地址:http://docs.jpush ...

  7. 极光推送 JPush 简介 集成 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. 极光推送Jpush(v3)服务端PHP版本的api脚本类

    原文地址:http://www.dodobook.net/php/780 关于极光推送的上一篇文章已经说明了,此处就不多说了.使用v3版本的原因是v2使用到2014年年底就停止了.点击查看上一篇的地址 ...

  9. Ionic5整合极光推送JPush ( 简单 )

    项目初始化 1. 安装项目依赖: # 安装cordova插件 ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=&qu ...

随机推荐

  1. 14、序列化操作,类的保存和dict转JSON

    在程序运行的过程中,所有的变量都是在内存中,比如,定义一个dict: d = dict(name='Bob', age=20, score=88) 可以随时修改变量,比如把name改成'Bill',但 ...

  2. HDU 2063 过山车 第一道最大二分匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=2063 题目大意: m个女生和n个男生一起做过山车,每一排必须一男一女,而每个女孩愿意和一些男生坐一起,, 你要找 ...

  3. GPUImage ==> 一个基于GPU图像和视频处理的开源iOS框架

    Logo 项目介绍: GPUImage是Brad Larson在github托管的开源项目. GPUImage是一个基于GPU图像和视频处理的开源iOS框架,提供各种各样的图像处理滤镜,并且支持照相机 ...

  4. Web--CSS控制页面(link与import方式差别)

        先了解: [1]         "Table"和"DIV"这两个网页元素诞生的目的不同,首先Table诞生的目的是为了存储数据,而DIV诞生的目的就是 ...

  5. ajax日期參数格式问题

    今天遇到ajax传输日期參数后台无法识别的问题,错误异常例如以下. 从异常中能够看出传输到后台的日期数据格式为Thu Aug 13 2015 19:45:20 GMT+0800 (中国标准时间),这样 ...

  6. Let's do our own full blown HTTP server with Netty--转载

    原文地址:http://adolgarev.blogspot.com/2013/12/lets-do-our-own-full-blown-http-server.html Sometimes ser ...

  7. vuex概念总结及简单使用实例

    原文 简书原文:https://www.jianshu.com/p/0546983f5997 大纲 1.什么是Vuex 2.什么是“状态管理模式”? 3.什么情况下应该使用 Vuex? 4.Vuex和 ...

  8. AE地图查询

    原文 AE地图查询 地图查询主要有两种查询:空间查询和属性查询 所用到知识点: 1  Cursor(游标)对象 本质上是一个指向数据的指针,本身不包含数据内容,提供一个连接到ROW对象或者要素对象(F ...

  9. php课程 1-3 字符串变量输出方式有哪些(总结:四种)

    php课程 1-3 字符串变量输出方式有哪些(总结:四种) 一.总结 一句话总结:推荐使用双引号中加{$变量名}的形式(echo "my name is {$name}eee !" ...

  10. POJ 1163 The Triangle 简单DP

    看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...