app-starlock/ios/Runner/AppDelegate.m

174 lines
6.4 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>
2025-01-09 19:35:02 +08:00
// #import <UMCommon/UMCommon.h>
@interface AppDelegate()
2025-02-13 10:56:24 +08:00
@property (nonatomic, strong) FlutterMethodChannel *methodChannel;
@end
@implementation AppDelegate {
}
2023-07-10 17:50:31 +08:00
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2025-01-09 19:35:02 +08:00
// [UMConfigure initWithAppkey:@"671244ae80464b33f6df9646" channel:@"Product"];
2025-02-13 10:56:24 +08:00
//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<UNNotificationCategory *> *categories for iOS10 or later
// NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
}
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
XSFlutterManager *VC = [[XSFlutterManager alloc] init];
self.window.rootViewController = VC;
[self.window makeKeyAndVisible];
2025-02-13 10:56:24 +08:00
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;
}
/**
* 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)];
}
}
/*
* deviceTokenCloudPush
*/
//- (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 {
2025-02-13 10:56:24 +08:00
//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);
}
2025-02-13 10:56:24 +08:00
# 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); // BadgeSoundAlert
}
// 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];
}
2023-07-10 17:50:31 +08:00
@end