AppDelegate.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // AppDelegate.m
  3. // AJPushDemo
  4. //
  5. // Created by Black on 2021/2/3.
  6. // Copyright © 2018 anji-plus 安吉加加信息技术有限公司 http://www.anji-plus.com. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ViewController.h"
  10. #import "SettingManager.h"
  11. #import <AJPushSDK/AJPushSDK.h>
  12. //#define APPSP_APPKEY @"fae48dd5c3834ff4aac9a12e79b0b481" //appsp推送 开发服务key
  13. //#define APPSP_APPKEY @"368696029b144826b1db71dd08da790e" //appsp推送 测试服务key
  14. #define APPSP_APPKEY @"3fffc7ab4e704965b3d7ebc034addef7" //appsp推送 uat服务key
  15. #define APPSP_SECRETKEY @"12d606b4ab5b496992c48048e2a035f1" //appsp推送 uat服务Secret Key
  16. #define JG_APPKEY @"66c9266fc53b8025cb0dd919" //极光推送服务key
  17. #define JG_CHANNEL @"App Store" //极光推送通道
  18. #define JG_IS_PRODUCTION 0 //0(默认值)表示采用的是开发证书,1 表示采用生产证书发布应用。
  19. //#define AppSpTestURL @"http://appsp.dev.anji-plus.com" //dev
  20. //#define AppSpTestURL @"http://appsp.test.anji-plus.com" //test
  21. #define AppSpTestURL @"https://openappsp.anji-plus.com" //uat
  22. @interface AppDelegate ()
  23. @end
  24. @implementation AppDelegate
  25. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  26. self.window = [[UIWindow alloc] initWithFrame: UIScreen.mainScreen.bounds];
  27. ViewController *vc = [ViewController new];
  28. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  29. self.window.rootViewController = nav;
  30. [self.window makeKeyAndVisible];
  31. //初始化配置信息
  32. [self initSettingData];
  33. //初始化推送服务
  34. [self initAPNSWithOptions:launchOptions];
  35. return YES;
  36. }
  37. //注册 APNs 成功并上报 DeviceToken
  38. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  39. NSLog(@"++application didRegisterForRemoteNotificationsWithDeviceToken");
  40. [[AJPushService shareService] registerDeviceToken:deviceToken withUrl:[SettingManager getAppSpUrl]];
  41. }
  42. //实现注册 APNs 失败接口
  43. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  44. //Optional
  45. NSLog(@"++did Fail To Register For Remote Notifications With Error: %@", error);
  46. }
  47. //初始化配置信息
  48. - (void)initSettingData {
  49. if([SettingManager getJPushKey] == nil) {
  50. [SettingManager setJPushKey:JG_APPKEY];
  51. }
  52. if([SettingManager getAppSpKey] == nil) {
  53. [SettingManager setAppSpKey:APPSP_APPKEY];
  54. }
  55. if ([SettingManager getAppSpUrl] == nil) {
  56. [SettingManager setAppSpUrl:AppSpTestURL];
  57. }
  58. if ([SettingManager getAppSpSecretKey] == nil) {
  59. [SettingManager setAppSpSecretKey:APPSP_SECRETKEY];
  60. }
  61. }
  62. //初始化推送服务
  63. - (void)initAPNSWithOptions:(NSDictionary *)launchOptions {
  64. [[AJPushService shareService] registerJPushOption:launchOptions appKey:[SettingManager getJPushKey] ajAppKey:[SettingManager getAppSpKey] channel:JG_CHANNEL apsForProduction:JG_IS_PRODUCTION];
  65. }
  66. @end