AppDelegate.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "AppDelegate.h"
  10. #import <React/RCTBundleURLProvider.h>
  11. #import <React/RCTRootView.h>
  12. #import <NIMSDK/NIMSDK.h>
  13. #import "RCCManager.h"
  14. #import "NTESSDKConfigDelegate.h"
  15. #import "DWCustomAttachmentDecoder.h"
  16. @interface AppDelegate ()
  17. @property (nonatomic,strong) NTESSDKConfigDelegate *sdkConfigDelegate;
  18. @end
  19. @implementation AppDelegate
  20. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  21. {
  22. NSURL *jsCodeLocation;
  23. jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  24. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  25. self.window.backgroundColor = [UIColor whiteColor];
  26. [[RCCManager sharedInstance] initBridgeWithBundleURL:jsCodeLocation launchOptions:launchOptions];
  27. //在注册 NIMSDK appKey 之前先进行配置信息的注册,如是否使用新路径,是否要忽略某些通知,是否需要多端同步未读数
  28. self.sdkConfigDelegate = [[NTESSDKConfigDelegate alloc] init];
  29. [[NIMSDKConfig sharedConfig] setDelegate:self.sdkConfigDelegate];
  30. [[NIMSDKConfig sharedConfig] setShouldSyncUnreadCount:YES];
  31. //appkey 是应用的标识,不同应用之间的数据(用户、消息、群组等)是完全隔离的。
  32. //如需打网易云信 Demo 包,请勿修改 appkey ,开发自己的应用时,请替换为自己的 appkey 。
  33. //并请对应更换 Demo 代码中的获取好友列表、个人信息等网易云信 SDK 未提供的接口。
  34. [[NIMSDK sharedSDK] registerWithAppID:@"8cafb31bb1c3750349340dec765df1c5" cerName:@"推送证书名称"];
  35. //注册自定义消息的解析器
  36. [NIMCustomObject registerCustomDecoder:[DWCustomAttachmentDecoder new]];
  37. [self registerAPNs];
  38. return YES;
  39. }
  40. #pragma mark - misc
  41. - (void)registerAPNs
  42. {
  43. [[UIApplication sharedApplication] registerForRemoteNotifications];
  44. UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
  45. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
  46. categories:nil];
  47. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  48. }
  49. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  50. {
  51. [[NIMSDK sharedSDK] updateApnsToken:deviceToken];
  52. }
  53. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
  54. NSLog(@"fail to get :%@",userInfo);
  55. }
  56. - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  57. {
  58. NSLog(@"fail to get apns token :%@",error);
  59. }
  60. - (void)applicationDidEnterBackground:(UIApplication *)application {
  61. NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
  62. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
  63. }
  64. @end