ApexMobileAppDelegate.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // ApexMobileAppDelegate.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-2-24.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ApexMobileAppDelegate.h"
  9. #import "ApexMobileDB.h"
  10. #import "ApexMobileNetwork.h"
  11. @implementation ApexMobileAppDelegate
  12. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  13. {
  14. // Override point for customization after application launch.
  15. [GMSServices provideAPIKey:@"AIzaSyBqS2pF7m1DlR5zwhAX_rBSD_9bTnpjYbQ"];
  16. if (! [ApexMobileDB initializeDb])
  17. // TODO: alert the user!
  18. DebugLog(@"couldn't init db");
  19. [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
  20. return YES;
  21. }
  22. -(void)Logout
  23. {
  24. self.user = nil;
  25. self.password=nil;
  26. self.sessionid=nil;
  27. [ApexMobileNetwork Logout];
  28. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  29. [defaults setBool:false forKey:@"autologin"];
  30. [defaults synchronize];
  31. //self.duid = nil;
  32. }
  33. - (void)applicationWillResignActive:(UIApplication *)application
  34. {
  35. // 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.
  36. // 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.
  37. }
  38. - (void)applicationDidEnterBackground:(UIApplication *)application
  39. {
  40. // 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.
  41. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  42. }
  43. - (void)applicationWillEnterForeground:(UIApplication *)application
  44. {
  45. // 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.
  46. }
  47. - (void)applicationDidBecomeActive:(UIApplication *)application
  48. {
  49. // 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.
  50. }
  51. - (void)applicationWillTerminate:(UIApplication *)application
  52. {
  53. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  54. }
  55. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)pToken {
  56. self.duid = [[[[NSString stringWithFormat:@"%@",pToken] substringWithRange:NSMakeRange(0, 72)] substringWithRange:NSMakeRange(1, 71)] stringByReplacingOccurrencesOfString:@" " withString:@""];
  57. NSLog(@"regisger success:%@",pToken);
  58. //注册成功,将deviceToken保存到应用服务器数据库中
  59. }
  60. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
  61. // 处理推送消息
  62. NSLog(@"userinfo:%@",userInfo);
  63. NSLog(@"收到推送消息:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
  64. }
  65. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  66. NSLog(@"Registfail%@",error);
  67. }
  68. @end