@interface AppDelegate () <UIApplicationDelegate>

@end

@implementation AppDelegate

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

/************ 检测通知 **************/

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

UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;

UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

} else {

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

}

return YES;

}

#pragma mark 消息推送模块

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

{

// re-post ( broadcast )

NSString *token = [[[[deviceToken description]

stringByReplacingOccurrencesOfString:@"<" withString:@""]

stringByReplacingOccurrencesOfString:@">" withString:@""]

stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *oldToken=[[NSUserDefaults standardUserDefaults]objectForKey:@"Token"];

if (![token isEqualToString:oldToken]) {

[[NSUserDefaults standardUserDefaults]setObject:token forKey:@"Token"];

[[NSUserDefaults standardUserDefaults]synchronize];

}

//给后台发送Token

/*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"token" message:token delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

alert.alertViewStyle = UIAlertViewStylePlainTextInput;

[alert textFieldAtIndex:0].text = token;

[alert show];*/

}

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

{

// re-post ( broadcast )

//[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];

NSLog(@">>>>注册远程推送失败<<<<");

}

//收到远程通知

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

{

if([UIApplication sharedApplication].applicationState == UIApplicationStateActive)

{

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

localNotification.alertAction = @"Ok";

localNotification.userInfo = userInfo;

localNotification.soundName = UILocalNotificationDefaultSoundName;

localNotification.alertBody = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

}

}

- (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.

}

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

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

- (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:.

}

iOS远程消息推送自我整理版的更多相关文章

  1. iOS远程消息推送原理

    1. 什么是远程消息推送? APNs:Apple Push Notification server 苹果推送通知服务苹果的APNs允许设备和苹果的推送通知服务器保持连接,支持开发者推送消息给用户设备对 ...

  2. 分分钟搞定IOS远程消息推送

    一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://my.oschina.net/u/2340880/blog/405491这篇博客中有详细的介绍,这里主要讨论远 ...

  3. iOS 远程消息推送,原理和开发详解篇(新手推荐)

    1.APNS的推送机制 首先我们看一下苹果官方给出的对ios推送机制的解释.如下图 Provider就是我们自己程序的后台服务器,APNS是Apple Push Notification Servic ...

  4. iOS远程消息推送

    iOS 推送基础知识 Apple 使用公共密钥数字证书对来自 iOS 应用程序的推送请求进行身份验证,所以您首先需要创建身份验证密钥,并向 Apple 注册它们.我将在下一节中花相当长的篇幅来直接介绍 ...

  5. iOS开发——远程消息推送的实现

    在我们使用App的过程中.总是会收到非常多的消息推送.今天我们就要来实现这个功能.首先消息推送分为本地消息推送和远程消息推送.而当中又以远程消息最为经常使用. 可是在推送远程消息之前.有两个前提条件. ...

  6. iOS开发笔记8:Remote Notification远程消息推送处理

    远程消息推送处理场景有三种:分别是app还没有运行.app在前台运行以及app在后台运行,下面介绍相关流程及三种场景下处理步骤 1.流程 (1)注册通知 首先是在注册远程消息推送,需要注意的是iOS8 ...

  7. iOS 10 消息推送(UserNotifications)秘籍总结(二)

    背景 上一篇博客iOS 10 消息推送(UserNotifications)秘籍总结(一)发布后被 简书编辑推荐至首页,这着实让我受宠若惊啊.可是好事不长,后面发生了让我伤心欲绝的事,我的女朋友不要我 ...

  8. iOS 10 消息推送(UserNotifications)秘籍总结(一)

    前言 之前说会单独整理消息通知的内容,但是因为工(就)作(是)的(很)事(懒)没有更新文章,违背了自己的学习的初衷.因为互联网一定要有危机意识,说不定眼一睁,我们就out丢了饭碗. 图片来源网络.jp ...

  9. iOS 之消息推送(个推)---个人小结

    前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术 ...

随机推荐

  1. 许令波老师的java的IO机制分析文章

    深入分析 Java I/O 的工作机制 I/O 问题可以说是当今互联网 Web 应用中所面临的主要问题之一,因为当前在这个海量数据时代,数据在网络中随处流动.这个流动的过程中都涉及到 I/O 问题,可 ...

  2. Light OJ 1031 - Easy Game(区间DP)

    题目大意: 给你一个n,代表n个数字,现在有两个选手,选手A,B轮流有有一次机会,每个选手一次可以得到一个或者多个数字,从左侧或者右侧,但是不能同时从两边取数字,当所有的数字被取完,那么游戏结束.然后 ...

  3. 数据结构(并查集||树链剖分):HEOI 2016 tree

    [注意事项] 为了体现增强版,题目限制和数据范围有所增强: 时间限制:1.5s 内存限制:128MB 对于15% 的数据,1<=N,Q<=1000. 对于35% 的数据,1<=N,Q ...

  4. MySQL安装没有弹出配置向导

    安装MySQL过程中一切都正常只是没有弹出MySQL配置向导对话框,即出现"launch the MySQL Instance Configuration Wizard" fini ...

  5. Unity3d fur真实毛发渲染

    放出效果图 使用的核心技术为曲面细分和置换贴图,Unity支持GPU的曲面细分,置换贴图为噪波,沿着法线拉伸即成为毛发.再随机减少最高点的高度产生毛刺的感觉 曲面细分之前有篇文章详细讲过 弄了前后ri ...

  6. Tree2cycle

    Problem Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, w ...

  7. 实现自己的脚本语言ngscript之一:词法分析

    正则表达式的理论基础可以参考装配脑袋的 这个 自己动手开发编译器(二)正则语言和正则表达式 这个 自己动手开发编译器(三)有穷自动机 还有这个 自己动手开发编译器(四)利用DFA转换表建立扫描器 如果 ...

  8. oracle从客户端到sql语句追踪

    这两天看小布老师的视频学习了一下从客户端到oracle数据库发送执行的SQL语句的跟踪,整理一下笔记. 需要用到的命令:netstat oracle端要用到的四个视图为: V$session:当前有多 ...

  9. 洛谷 P1026 统计单词个数

    题目描述 给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保证每行一定为20个).要求将此字母串分成k份(1<k<=40),且每份中包含的单 ...

  10. ng-repeat 遍历同值数组导致的报错

    http://blog.csdn.net/tyust512/article/details/50370624