app-starlock/ios/Runner/AppDelegate.m

153 lines
5.5 KiB
Mathematica
Raw Normal View History

2023-07-10 17:50:31 +08:00
#import "AppDelegate.h"
2023-07-10 17:50:31 +08:00
#import "GeneratedPluginRegistrant.h"
2023-10-14 17:08:25 +08:00
#import "CommonDefine.h"
#import "XSFlutterManager.h"
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate()
@end
@implementation AppDelegate {
}
2023-07-10 17:50:31 +08:00
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// //
// 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];
// [self initCloudPush];
// [CloudPushSDK sendNotificationAck:launchOptions];
XSFlutterManager *VC = [[XSFlutterManager alloc] init];
self.window.rootViewController = VC;
[self.window makeKeyAndVisible];
return YES;
2023-07-10 17:50:31 +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;
}
- (void)initCloudPush {
// SDK
[CloudPushSDK asyncInit:@"334068745" appSecret:@"bee9c200835e4951a85dc8709c319560" callback:^(CloudPushCallbackResult *res) {
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)];
}
}
/*
* deviceTokenCloudPush
*/
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// [CloudPushSDK registerDevice:deviceToken withCallback:^(CloudPushCallbackResult *res) {
// if (res.success) {
// NSLog(@"Register deviceToken success.");
// } else {
// NSLog(@"Register deviceToken failed, error: %@", res.error);
// }
// }];
//sdkDeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
/*
*
*/
- (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
*/
//- (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"]; //Extraskey
// 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-07-10 17:50:31 +08:00
@end