#import "AppDelegate.h" #import "GeneratedPluginRegistrant.h" #import "CommonDefine.h" #import "XSFlutterManager.h" #import // #import @interface AppDelegate() @property (nonatomic, strong) FlutterMethodChannel *methodChannel; @end @implementation AppDelegate { } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // [UMConfigure initWithAppkey:@"671244ae80464b33f6df9646" channel:@"Product"]; //Required //notice: 3.0.0 及以后版本注册可以这样写,也可以继续用之前的注册方式 JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { // 可以添加自定义 categories // NSSet *categories for iOS10 or later // NSSet *categories for iOS8 and iOS9 } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; XSFlutterManager *VC = [[XSFlutterManager alloc] init]; self.window.rootViewController = VC; [self.window makeKeyAndVisible]; return YES; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { // 判断是否是你的应用程序的 URL Scheme if ([url.scheme isEqualToString:@"skysmartlock"]) { // 处理被唤起的逻辑,可以根据 URL 中的其他信息来执行相应的操作 return YES; } return NO; } /** * 注册苹果推送,获取deviceToken用于推送 * * @param application */ - (void)registerAPNS:(UIApplication *)application { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { // iOS 8 Notifications [application registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]]; [application registerForRemoteNotifications]; } else { // iOS < 8 Notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; } } /* * 苹果推送注册成功回调,将苹果返回的deviceToken上传到CloudPush服务器 */ //- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // NSString *tokenString = [self hexStringFromData:deviceToken]; // NSLog(@"starlock didRegisterForRemoteNotificationsWithDeviceToken token: %@", tokenString); // /// Required - 注册 DeviceToken // [JPUSHService registerDeviceToken:deviceToken]; // //} - (NSString *)hexStringFromData:(NSData *)data { const unsigned char *dataBuffer = (const unsigned char *)[data bytes]; NSMutableString *hexString = [NSMutableString stringWithCapacity:data.length * 2]; for (NSInteger i = 0; i < data.length; i++) { [hexString appendFormat:@"%02x", dataBuffer[i]]; } return [hexString copy]; } /* * 苹果推送注册失败回调 */ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { //Optional NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } /** * 注册推送消息到来监听 */ - (void)registerMessageReceive { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageReceived:) name:@"CCPDidReceiveMessageNotification" object:nil]; } /** * 处理到来推送消息 * * @param notification */ - (void)onMessageReceived:(NSNotification *)notification { CCPSysMessage *message = [notification object]; NSString *title = [[NSString alloc] initWithData:message.title encoding:NSUTF8StringEncoding]; NSString *body = [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]; NSLog(@"Receive message title: %@, content: %@.", title, body); } # pragma mark- JPUSHRegisterDelegate // iOS 12 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification{ if (notification && [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { //从通知界面直接进入应用 }else{ //从通知设置界面进入应用 } } // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler { // Required NSDictionary * userInfo = notification.request.content.userInfo; if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置 } // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { // Required NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; } completionHandler(); // 系统要求执行这个方法 } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // Required, iOS 7 Support [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // Required, For systems with less than or equal to iOS 6 [JPUSHService handleRemoteNotification:userInfo]; } @end