2023-07-10 17:50:31 +08:00
|
|
|
|
#import "AppDelegate.h"
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
2023-07-10 17:50:31 +08:00
|
|
|
|
#import "GeneratedPluginRegistrant.h"
|
2023-10-14 17:08:25 +08:00
|
|
|
|
#import "CommonDefine.h"
|
2023-11-01 14:18:52 +08:00
|
|
|
|
#import "XSFlutterManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#import <UserNotifications/UserNotifications.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 18:26:07 +08:00
|
|
|
|
|
2023-11-01 14:18:52 +08:00
|
|
|
|
@interface AppDelegate()
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation AppDelegate {
|
|
|
|
|
|
}
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application
|
|
|
|
|
|
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
2024-03-19 18:26:07 +08:00
|
|
|
|
// //【注册通知】通知回调代理(可选)
|
|
|
|
|
|
// JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
|
|
|
|
|
|
// entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
|
|
|
|
|
|
// [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
|
|
|
|
|
|
//
|
|
|
|
|
|
// //【初始化sdk】
|
|
|
|
|
|
// // notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
|
|
|
|
|
|
// [JPUSHService setupWithOption:launchOptions appKey:@"7ff37d174c1a568a89e98dad"
|
|
|
|
|
|
// channel:@"flutter_channel"
|
|
|
|
|
|
// apsForProduction:NO
|
|
|
|
|
|
// advertisingIdentifier:nil];
|
|
|
|
|
|
|
2024-02-29 17:03:53 +08:00
|
|
|
|
// [self initCloudPush];
|
|
|
|
|
|
// [CloudPushSDK sendNotificationAck:launchOptions];
|
2023-11-01 14:18:52 +08:00
|
|
|
|
XSFlutterManager *VC = [[XSFlutterManager alloc] init];
|
2023-10-16 17:18:10 +08:00
|
|
|
|
self.window.rootViewController = VC;
|
|
|
|
|
|
[self.window makeKeyAndVisible];
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
2023-10-16 17:18:10 +08:00
|
|
|
|
return YES;
|
2023-07-10 17:50:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-17 14:29:13 +08:00
|
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
|
|
|
|
|
// 判断是否是你的应用程序的 URL Scheme
|
|
|
|
|
|
if ([url.scheme isEqualToString:@"skysmartlock"]) {
|
|
|
|
|
|
// 处理被唤起的逻辑,可以根据 URL 中的其他信息来执行相应的操作
|
|
|
|
|
|
return YES;
|
|
|
|
|
|
}
|
|
|
|
|
|
return NO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-01 14:18:52 +08:00
|
|
|
|
- (void)initCloudPush {
|
|
|
|
|
|
// SDK初始化
|
2024-03-19 18:26:07 +08:00
|
|
|
|
[CloudPushSDK asyncInit:@"334068745" appSecret:@"bee9c200835e4951a85dc8709c319560" callback:^(CloudPushCallbackResult *res) {
|
2023-11-01 14:18:52 +08:00
|
|
|
|
if (res.success) {
|
|
|
|
|
|
NSLog(@"Push SDK init success, deviceId: %@.", [CloudPushSDK getDeviceId]);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
NSLog(@"Push SDK init failed, error: %@", res.error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 注册苹果推送,获取deviceToken用于推送
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param application
|
|
|
|
|
|
*/
|
|
|
|
|
|
- (void)registerAPNS:(UIApplication *)application {
|
|
|
|
|
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
|
|
|
|
|
|
// iOS 8 Notifications
|
|
|
|
|
|
[application registerUserNotificationSettings:
|
|
|
|
|
|
[UIUserNotificationSettings settingsForTypes:
|
|
|
|
|
|
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
|
|
|
|
|
|
categories:nil]];
|
|
|
|
|
|
[application registerForRemoteNotifications];
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
// iOS < 8 Notifications
|
|
|
|
|
|
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
|
|
|
|
|
|
(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 苹果推送注册成功回调,将苹果返回的deviceToken上传到CloudPush服务器
|
|
|
|
|
|
*/
|
|
|
|
|
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
2024-03-19 18:26:07 +08:00
|
|
|
|
// [CloudPushSDK registerDevice:deviceToken withCallback:^(CloudPushCallbackResult *res) {
|
|
|
|
|
|
// if (res.success) {
|
|
|
|
|
|
// NSLog(@"Register deviceToken success.");
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// NSLog(@"Register deviceToken failed, error: %@", res.error);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }];
|
|
|
|
|
|
//sdk注册DeviceToken
|
|
|
|
|
|
[JPUSHService registerDeviceToken:deviceToken];
|
|
|
|
|
|
|
2023-11-01 14:18:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 苹果推送注册失败回调
|
|
|
|
|
|
*/
|
|
|
|
|
|
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
|
|
|
|
|
|
NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* App处于启动状态时,通知打开回调
|
|
|
|
|
|
*/
|
2024-04-28 14:12:50 +08:00
|
|
|
|
//- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
|
|
|
|
|
|
// NSLog(@"Receive one notification.");
|
|
|
|
|
|
// 取得APNS通知内容
|
|
|
|
|
|
// NSDictionary *aps = [userInfo valueForKey:@"aps"];
|
|
|
|
|
|
// // 内容
|
|
|
|
|
|
// NSString *content = [aps valueForKey:@"alert"];
|
|
|
|
|
|
// // badge数量
|
|
|
|
|
|
// NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
|
|
|
|
|
|
// // 播放声音
|
|
|
|
|
|
// NSString *sound = [aps valueForKey:@"sound"];
|
|
|
|
|
|
// // 取得Extras字段内容
|
|
|
|
|
|
// NSString *Extras = [userInfo valueForKey:@"Extras"]; //服务端中Extras字段,key是自己定义的
|
|
|
|
|
|
// NSLog(@"content = [%@], badge = [%ld], sound = [%@], Extras = [%@]", content, (long)badge, sound, Extras);
|
|
|
|
|
|
// // iOS badge 清0
|
|
|
|
|
|
// application.applicationIconBadgeNumber = 0;
|
|
|
|
|
|
// // 通知打开回执上报
|
|
|
|
|
|
// // [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1)
|
|
|
|
|
|
// [CloudPushSDK sendNotificationAck:userInfo];
|
|
|
|
|
|
//}
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-10 17:50:31 +08:00
|
|
|
|
@end
|