Leon há 1 ano atrás
pai
commit
d1a0fcb5a3
3 ficheiros alterados com 23 adições e 69 exclusões
  1. 17 15
      ios/AppDelegate.mm
  2. 4 54
      ios/NativeBridge.m
  3. 2 0
      ios/hola/hola.entitlements

+ 17 - 15
ios/AppDelegate.mm

@@ -34,10 +34,10 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
 
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
-//  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenNotificationSettingsURLString]];
-//  NSString *url = UIApplicationOpenNotificationSettingsURLString;
+  //  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenNotificationSettingsURLString]];
+  //  NSString *url = UIApplicationOpenNotificationSettingsURLString;
   // APNS
-//  BOOL isLocation = [CLLocationManager locationServicesEnabled];
+  //  BOOL isLocation = [CLLocationManager locationServicesEnabled];
   self.rnLoaded = NO;
   NSDate *date = [NSDate date];
   //zone为当前时区信息  在我的程序中打印的是@"Asia/Shanghai"
@@ -46,20 +46,20 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
   NSInteger interval = [zone secondsFromGMTForDate: date];
   //加上时差,得到本地时间
   NSDate *localeDate = [date dateByAddingTimeInterval: interval];
-
-//    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
-//    if (@available(iOS 12.0, *)) {
-//      entity.types = JPAuthorizationOptionNone; //JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSou//nd|JPAuthorizationOptionProvidesAppNotificationSettings;
-//    }
-//    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
+  
+  //    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
+  //    if (@available(iOS 12.0, *)) {
+  //      entity.types = JPAuthorizationOptionNone; //JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSou//nd|JPAuthorizationOptionProvidesAppNotificationSettings;
+  //    }
+  //    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
   
   RCTAppSetupPrepareApp(application);
-
+  
   RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
   
   UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
   center.delegate = self;
-
+  
 #if RCT_NEW_ARCH_ENABLED
   _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
   _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
@@ -67,16 +67,16 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
   _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
   bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
 #endif
-
+  
   NSDictionary *initProps = [self prepareInitialProps];
   UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"taroDemo" initialProperties:initProps];
-
+  
   if (@available(iOS 13.0, *)) {
     rootView.backgroundColor = [UIColor systemBackgroundColor];
   } else {
     rootView.backgroundColor = [UIColor blackColor];
   }
-
+  
   self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
   self.window.backgroundColor = [UIColor blackColor];
   UIViewController *rootViewController = [self.reactDelegate createRootViewController];
@@ -91,7 +91,9 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
   return YES;
 }
 
-
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+  [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
+}
 - (void)registerForPushNotifications {
     UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
     [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {

+ 4 - 54
ios/NativeBridge.m

@@ -142,60 +142,6 @@ RCT_EXPORT_METHOD(authNotification){
   });
 }
 
-RCT_EXPORT_METHOD(addLocalPush2:(id)detail){
-  dispatch_async(dispatch_get_main_queue(), ^{
-    //设置通知内容
-    UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
-    content.title = @"a1";
-    content.body = @"b1";
-    
-    UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"START_TIMER_NOW1" title:@"Start timer now with 1-tap" options:UNNotificationActionOptionForeground];
-    
-    UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_START2" title:@"Pick an earlier start" options:UNNotificationActionOptionForeground];
-    NSArray *actions = @[action1,action2];
-    
-    
-    UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:@"c1" actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
-    
-    //    [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
-    content.categoryIdentifier = @"c1";
-    
-    UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO];
-    NSString * identifier = @"e1";
-    UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
-    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
-      
-    }];
-    
-    UNMutableNotificationContent * content2 = [[UNMutableNotificationContent alloc] init];
-    content2.title = @"a12";
-    content2.body = @"b12";
-    
-    NSArray *actions2;
-    
-    UNNotificationAction *action12 = [UNNotificationAction actionWithIdentifier:@"START_TIMER_NOW" title:@"Start timer now with 1-tap" options:UNNotificationActionOptionForeground];
-    
-    UNNotificationAction *action22 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_START" title:@"Pick an earlier start" options:UNNotificationActionOptionForeground];
-    
-    UNNotificationAction *action32 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
-    actions2 = @[action12,action22,action32];
-    
-    
-    UNNotificationCategory *categroy2 = [UNNotificationCategory categoryWithIdentifier:@"c12" actions:actions2 intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
-    
-    //    [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy2]];
-    [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:@[categroy,categroy2]]];
-    content2.categoryIdentifier = @"c12";
-    
-    UNTimeIntervalNotificationTrigger * trigger2 = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:15 repeats:NO];
-    NSString * identifier2 = @"e12";
-    UNNotificationRequest * request2 = [UNNotificationRequest requestWithIdentifier:identifier2 content:content2 trigger:trigger2];
-    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request2 withCompletionHandler:^(NSError * _Nullable error) {
-    }];
-    
-  });
-}
-
 
 RCT_EXPORT_METHOD(addLocalPush:(id)array){
   dispatch_async(dispatch_get_main_queue(), ^{
@@ -223,6 +169,10 @@ RCT_EXPORT_METHOD(addLocalPush:(id)array){
       content.title = detail[@"title"];
       content.body = [NSString stringWithFormat:@"%@\nPress for actions >>",detail[@"body"]];
       content.sound = [UNNotificationSound defaultSound];
+      content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
+      if (@available(iOS 15.0,*)){
+        content.interruptionLevel = UNNotificationInterruptionLevelTimeSensitive;
+      }
       
       NSString *category_id = detail[@"category_id"];
       NSString *message_id = detail[@"id"];

+ 2 - 0
ios/hola/hola.entitlements

@@ -4,5 +4,7 @@
 <dict>
 	<key>aps-environment</key>
 	<string>development</string>
+	<key>com.apple.developer.usernotifications.time-sensitive</key>
+	<true/>
 </dict>
 </plist>