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

}

最新文章

  1. 计算机程序的思维逻辑 (39) - 剖析LinkedList
  2. Apache的dbutils的架构图
  3. HDFS snapshot操作实战
  4. CentOS编译安装NodeJS+Express
  5. cookie的作用
  6. jquery on()方法绑定多个选择器,多个事件
  7. zt:如何快速赚取人生第一个100万?
  8. MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)
  9. Python基础10 反过头来看看
  10. HDU 1505 City Game
  11. [codility]Falling-discs
  12. NOI2015 程序自动分析
  13. [置顶] API相关工作过往的总结之Sandcastle简要使用介绍
  14. sql求和涉及到null值
  15. 手把手教你学习FPGA系列视频教程_救护车鸣笛声
  16. NuttX 介绍
  17. Humming Bird A20 SPI2驱动编译
  18. 【Coucurrency-CountDownLatch】-20161203-0002
  19. sqlserver 分割字符串和调用
  20. Shell获取某目录下所有文件夹的名称

热门文章

  1. IN改写关联注意事项!
  2. [LeetCode#128]Word Ladder II
  3. bzoj2165
  4. HTTP 错误 500.21 - Internal Server Error处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
  5. Win10开发必备:Visual Studio 2015正式版下载
  6. Linq to SQL 类型的对象图包含循环,如果禁用引用跟踪,择无法对其进行序列化。
  7. Linux学习笔记28——消息队列
  8. [Git] Github客户端上publish后一直转圈,web上未上传成功
  9. ADO数据库链接
  10. 利用Trie树对字符串集合进行排序并计算特征值