AppDelegate.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. #import "AppDelegate.h"
  2. #import <React/RCTBridge.h>
  3. #import <React/RCTBundleURLProvider.h>
  4. #import <React/RCTRootView.h>
  5. #import <React/RCTAppSetupUtils.h>
  6. #import <CoreLocation/CoreLocation.h>
  7. //#import <RCTJPushModule.h>
  8. #if RCT_NEW_ARCH_ENABLED
  9. #import <React/CoreModulesPlugins.h>
  10. #import <React/RCTCxxBridgeDelegate.h>
  11. #import <React/RCTFabricSurfaceHostingProxyRootView.h>
  12. #import <React/RCTSurfacePresenter.h>
  13. #import <React/RCTSurfacePresenterBridgeAdapter.h>
  14. #import <ReactCommon/RCTTurboModuleManager.h>
  15. #import <react/config/ReactNativeConfig.h>
  16. #import <AVFoundation/AVFoundation.h>
  17. static NSString *const kRNConcurrentRoot = @"concurrentRoot";
  18. @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
  19. RCTTurboModuleManager *_turboModuleManager;
  20. RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
  21. std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
  22. facebook::react::ContextContainer::Shared _contextContainer;
  23. }
  24. @end
  25. #endif
  26. @interface AppDelegate()
  27. @property (nonatomic, strong) AVAudioPlayer *audioPlayer;
  28. @end
  29. @implementation AppDelegate
  30. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  31. {
  32. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenNotificationSettingsURLString]];
  33. // NSString *url = UIApplicationOpenNotificationSettingsURLString;
  34. // APNS
  35. // BOOL isLocation = [CLLocationManager locationServicesEnabled];
  36. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  37. [center removeAllPendingNotificationRequests];
  38. self.rnLoaded = NO;
  39. NSDate *date = [NSDate date];
  40. //zone为当前时区信息 在我的程序中打印的是@"Asia/Shanghai"
  41. NSTimeZone *zone = [NSTimeZone systemTimeZone];
  42. //所在地区时间与协调世界时差距
  43. NSInteger interval = [zone secondsFromGMTForDate: date];
  44. //加上时差,得到本地时间
  45. NSDate *localeDate = [date dateByAddingTimeInterval: interval];
  46. // JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
  47. // if (@available(iOS 12.0, *)) {
  48. // entity.types = JPAuthorizationOptionNone; //JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSou//nd|JPAuthorizationOptionProvidesAppNotificationSettings;
  49. // }
  50. // [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
  51. RCTAppSetupPrepareApp(application);
  52. RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
  53. // UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  54. center.delegate = self;
  55. #if RCT_NEW_ARCH_ENABLED
  56. _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
  57. _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
  58. _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
  59. _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
  60. bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
  61. #endif
  62. NSDictionary *initProps = [self prepareInitialProps];
  63. UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"taroDemo" initialProperties:initProps];
  64. if (@available(iOS 13.0, *)) {
  65. rootView.backgroundColor = [UIColor systemBackgroundColor];
  66. } else {
  67. rootView.backgroundColor = [UIColor blackColor];
  68. }
  69. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  70. self.window.backgroundColor = [UIColor blackColor];
  71. UIViewController *rootViewController = [self.reactDelegate createRootViewController];
  72. rootViewController.view = rootView;
  73. rootViewController.view.backgroundColor = [UIColor blackColor];
  74. self.window.rootViewController = rootViewController;
  75. [self.window makeKeyAndVisible];
  76. [super application:application didFinishLaunchingWithOptions:launchOptions];
  77. [self clearAllDeliveredNotifications];
  78. [self mixAudio];
  79. return YES;
  80. }
  81. - (void)mixAudio{
  82. NSError *error = nil;
  83. AVMutableComposition *composition = [AVMutableComposition composition];
  84. // 创建音轨
  85. AVMutableCompositionTrack *compositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
  86. // 声音文件路径
  87. NSString *soundFilePath1 = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"m4a"];
  88. NSString *soundFilePath2 = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"m4a"];
  89. // 加载音频文件
  90. AVAsset *asset1 = [AVAsset assetWithURL:[NSURL fileURLWithPath:soundFilePath1]];
  91. AVAsset *asset2 = [AVAsset assetWithURL:[NSURL fileURLWithPath:soundFilePath2]];
  92. // 获取音频文件的时长
  93. CMTimeRange timeRange1 = CMTimeRangeMake(kCMTimeZero, asset1.duration);
  94. CMTimeRange timeRange2 = CMTimeRangeMake(kCMTimeZero, asset2.duration);
  95. // 将音频文件的音轨添加到合成的音轨中
  96. [compositionTrack insertTimeRange:timeRange1 ofTrack:[[asset1 tracksWithMediaType:AVMediaTypeAudio] firstObject] atTime:kCMTimeZero error:&error];
  97. if (error) {
  98. // 错误处理
  99. NSLog(@"Error composing sound: %@", [error localizedDescription]);
  100. }
  101. // 在第一段声音之后继续添加第二段声音
  102. [compositionTrack insertTimeRange:timeRange2 ofTrack:[[asset2 tracksWithMediaType:AVMediaTypeAudio] firstObject] atTime:asset1.duration error:&error];
  103. if (error) {
  104. // 错误处理
  105. NSLog(@"Error composing sound: %@", [error localizedDescription]);
  106. }
  107. // 输出文件路径
  108. NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"outputSound.m4a"];
  109. NSFileManager *fileManager = [NSFileManager defaultManager];
  110. BOOL fileExists = [fileManager fileExistsAtPath:outputFilePath];
  111. if (fileExists) {
  112. // 文件存在,删除文件
  113. NSError *error;
  114. BOOL success = [fileManager removeItemAtPath:outputFilePath error:&error];
  115. if (success) {
  116. NSLog(@"文件删除成功");
  117. } else {
  118. // 处理错误
  119. NSLog(@"文件删除失败: %@", [error localizedDescription]);
  120. }
  121. } else {
  122. NSLog(@"文件不存在");
  123. }
  124. NSURL *outputURL = [NSURL fileURLWithPath:outputFilePath];
  125. // 导出合成的音频
  126. AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetAppleM4A];
  127. exportSession.outputURL = outputURL;
  128. exportSession.outputFileType = AVFileTypeAppleM4A;
  129. [exportSession exportAsynchronouslyWithCompletionHandler:^{
  130. if (exportSession.status == AVAssetExportSessionStatusCompleted) {
  131. // 导出成功,可以播放或者使用输出的文件
  132. NSLog(@"Export success: %@", outputFilePath);
  133. NSURL *fileURL = [NSURL fileURLWithPath:outputFilePath];
  134. NSError *error;
  135. self->_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
  136. if (error) {
  137. NSLog(@"Error creating audio player: %@", [error localizedDescription]);
  138. } else {
  139. [self->_audioPlayer play];
  140. }
  141. } else {
  142. // 导出失败,处理错误
  143. NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
  144. }
  145. }];
  146. }
  147. - (void)applicationDidBecomeActive:(UIApplication *)application {
  148. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  149. }
  150. - (void)registerForPushNotifications {
  151. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  152. [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
  153. if (granted) {
  154. dispatch_async(dispatch_get_main_queue(), ^{
  155. [[UIApplication sharedApplication] registerForRemoteNotifications];
  156. });
  157. } else {
  158. // 用户拒绝通知或发生错误
  159. }
  160. }];
  161. }
  162. /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
  163. ///
  164. /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
  165. /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
  166. /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
  167. - (BOOL)concurrentRootEnabled
  168. {
  169. // Switch this bool to turn on and off the concurrent root
  170. return true;
  171. }
  172. - (NSDictionary *)prepareInitialProps
  173. {
  174. NSMutableDictionary *initProps = [NSMutableDictionary new];
  175. #ifdef RCT_NEW_ARCH_ENABLED
  176. initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
  177. #endif
  178. return initProps;
  179. }
  180. - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
  181. {
  182. // return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  183. #if DEBUG
  184. return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  185. #else
  186. return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  187. #endif
  188. }
  189. #if RCT_NEW_ARCH_ENABLED
  190. #pragma mark - RCTCxxBridgeDelegate
  191. - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
  192. {
  193. _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
  194. delegate:self
  195. jsInvoker:bridge.jsCallInvoker];
  196. return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
  197. }
  198. #pragma mark RCTTurboModuleManagerDelegate
  199. - (Class)getModuleClassFromName:(const char *)name
  200. {
  201. return RCTCoreModulesClassProvider(name);
  202. }
  203. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  204. jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
  205. {
  206. return nullptr;
  207. }
  208. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  209. initParams:
  210. (const facebook::react::ObjCTurboModule::InitParams &)params
  211. {
  212. return nullptr;
  213. }
  214. - (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
  215. {
  216. return RCTAppSetupDefaultModuleFromClass(moduleClass);
  217. }
  218. #endif
  219. //************************************************JPush start************************************************
  220. //注册 APNS 成功并上报 DeviceToken
  221. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  222. // [JPUSHService registerDeviceToken:deviceToken];
  223. }
  224. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
  225. NSLog(@"get notification error");
  226. }
  227. //iOS 7 APNS
  228. - (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  229. // iOS 10 以下 Required
  230. NSLog(@"iOS 7 APNS");
  231. // [JPUSHService handleRemoteNotification:userInfo];
  232. // [[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_ARRIVED_EVENT object:userInfo];
  233. completionHandler(UIBackgroundFetchResultNewData);
  234. }
  235. //iOS 10 前台收到消息
  236. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
  237. NSDictionary * userInfo = notification.request.content.userInfo;
  238. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  239. // Apns
  240. NSLog(@"iOS 10 APNS 前台收到消息");
  241. // [JPUSHService handleRemoteNotification:userInfo];
  242. // [[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_ARRIVED_EVENT object:userInfo];
  243. }
  244. else {
  245. // 本地通知 todo
  246. NSLog(@"iOS 10 本地通知 前台收到消息");
  247. // [[NSNotificationCenter defaultCenter] postNotificationName:J_LOCAL_NOTIFICATION_ARRIVED_EVENT object:userInfo];
  248. }
  249. //需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置
  250. completionHandler(UNNotificationPresentationOptionAlert);
  251. }
  252. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  253. }
  254. //再实现UNUserNotificationCenterDelegate代理的方法
  255. //- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
  256. //{
  257. // //应用在前台时候接收到本地推送通知、远程推送通知调用此方法
  258. //}
  259. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler
  260. {
  261. //应用程序在后台,用户通过点击本地推送、远程推送进入app时调用此方法
  262. self.timestamp = [[NSDate date] timeIntervalSince1970]*1000;
  263. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(postNotificationData:) userInfo:response repeats:YES];
  264. }
  265. //iOS 10 消息事件回调
  266. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler: (void (^)(void))completionHandler {
  267. NSDictionary * userInfo = response.notification.request.content.userInfo;
  268. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  269. // Apns
  270. NSLog(@"iOS 10 APNS 消息事件回调");
  271. // [JPUSHService handleRemoteNotification:userInfo];
  272. // // 保障应用被杀死状态下,用户点击推送消息,打开app后可以收到点击通知事件
  273. // [[RCTJPushEventQueue sharedInstance]._notificationQueue insertObject:userInfo atIndex:0];
  274. // [[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_OPENED_EVENT object:userInfo];
  275. }
  276. else {
  277. // 本地通知
  278. NSLog(@"iOS 10 本地通知 消息事件回调");
  279. // 保障应用被杀死状态下,用户点击推送消息,打开app后可以收到点击通知事件
  280. // [[RCTJPushEventQueue sharedInstance]._localNotificationQueue insertObject:userInfo atIndex:0];
  281. // [[NSNotificationCenter defaultCenter] postNotificationName:J_LOCAL_NOTIFICATION_OPENED_EVENT object:userInfo];
  282. }
  283. self.timestamp = [[NSDate date] timeIntervalSince1970]*1000;
  284. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(postNotificationData:) userInfo:response repeats:YES];
  285. // NSString *categoryIdentifier = response.notification.request.content.categoryIdentifier;
  286. // [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"notificationReceive" body:@{@"category_id":categoryIdentifier,@"action_id":response.actionIdentifier}];
  287. // 处理用户交互
  288. // if ([response.actionIdentifier isEqualToString:@"ALLOW_ACTION"]) {
  289. // // 用户点击了"允许"按钮,发起网络请求
  290. // NSLog(@"User allow the request");
  291. //
  292. //// [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"notificationReceive" body:@{@"name":@"1",@"value":@"2"}];
  293. //
  294. //// [self makeNetworkRequest];
  295. // } else if ([response.actionIdentifier isEqualToString:@"DENY_ACTION"]) {
  296. // // 用户点击了"拒绝"按钮
  297. // NSLog(@"User denied the request");
  298. //// [self makeNetworkRequest];
  299. // } else if ([response.actionIdentifier isEqualToString:@"START_TIMER_NOW"]){
  300. // if ([categoryIdentifier isEqualToString:@"REMINDER_FS_START_FAST"]){
  301. //
  302. // }
  303. // else if ([categoryIdentifier isEqualToString:@"REMINDER_FS_START_SLEEP"]){
  304. //
  305. // }
  306. // } else if ([response.actionIdentifier isEqualToString:@"PICK_EARLIER_START"]){
  307. // if ([categoryIdentifier isEqualToString:@"REMINDER_FS_START_FAST"]){
  308. //
  309. // }
  310. // else if ([categoryIdentifier isEqualToString:@"REMINDER_FS_START_SLEEP"]){
  311. //
  312. // }
  313. // }
  314. // else if ([response.actionIdentifier isEqualToString:@"END_TIMER_NOW"]){
  315. //
  316. // }
  317. // else if ([response.actionIdentifier isEqualToString:@"PICK_EARLIER_END"]){
  318. //
  319. // }
  320. // else if ([response.actionIdentifier isEqualToString:@"SKIP"]){
  321. //
  322. // }
  323. // 系统要求执行这个方法
  324. completionHandler();
  325. }
  326. - (void)postNotificationData:(NSTimer *)timerInfo{
  327. if (self.rnLoaded){
  328. UNNotificationResponse *response = timerInfo.userInfo;
  329. [self.timer invalidate];
  330. self.timer = nil;
  331. NSString *categoryIdentifier = response.notification.request.content.categoryIdentifier;
  332. NSString *identifier = response.notification.request.identifier;
  333. if ([identifier hasPrefix:@"REMINDER_FS_"]){
  334. NSString *strId = [identifier substringFromIndex:12];
  335. [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"notificationReceive" body:@{@"category_id":categoryIdentifier,@"action_id":response.actionIdentifier,@"id":strId,@"timestamp":@(self.timestamp)}];
  336. [self clearAllDeliveredNotifications];
  337. }
  338. }
  339. else {
  340. }
  341. }
  342. - (void)jumpNotificationSettingPage{
  343. if (self.rnLoaded){
  344. [self.timer invalidate];
  345. self.timer = nil;
  346. [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"openNotificationSetting" body:@{}];
  347. }
  348. else {
  349. }
  350. }
  351. - (void)makeNetworkRequest{
  352. //https://api.fast.dev.liveplus.fun/api/static-resource-urls
  353. NSURL *url = [NSURL URLWithString:@"https://api.fast.dev.liveplus.fun/api/static-resource-urls"];
  354. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  355. NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  356. if (error) {
  357. NSLog(@"Error: %@", error.localizedDescription);
  358. } else {
  359. // 处理返回的数据
  360. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  361. NSLog(@"Response: %@", json);
  362. }
  363. }];
  364. [dataTask resume];
  365. }
  366. //自定义消息
  367. - (void)networkDidReceiveMessage:(NSNotification *)notification {
  368. NSDictionary * userInfo = [notification userInfo];
  369. // [[NSNotificationCenter defaultCenter] postNotificationName:J_CUSTOM_NOTIFICATION_EVENT object:userInfo];
  370. }
  371. - (void)demo{
  372. // 1. 设置 notification 内容
  373. UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
  374. content.title = @"Daily Reminder";
  375. content.body = @"It's 9:00 AM, time to start your day!";
  376. content.sound = [UNNotificationSound defaultSound];
  377. // 2. 设置触发条件 - 每天 9:00 AM
  378. NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
  379. dateComponents.hour = 9;
  380. dateComponents.minute = 0;
  381. UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
  382. // 3. 创建 notification request
  383. UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"DailyReminder" content:content trigger:trigger];
  384. // 4. 添加 notification request 到通知中心
  385. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  386. [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
  387. if (error != nil) {
  388. NSLog(@"Error adding notification request: %@", error);
  389. }
  390. }];
  391. }
  392. - (void)scheduleCalendarNotificationWithTitle:(NSString *)title body:(NSString *)body date:(NSDate *)date repeats:(BOOL)repeats identifier:(NSString *)identifier {
  393. NSLog(@"%s", __FUNCTION__);
  394. UNMutableNotificationContent *content = [UNMutableNotificationContent new];
  395. content.title = title;
  396. content.body = body;
  397. NSCalendar *calendar = NSCalendar.currentCalendar;
  398. NSDateComponents *components = [calendar components:(NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:date];
  399. UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:repeats];
  400. UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
  401. [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
  402. if (error) {
  403. NSLog(@"%@", error);
  404. }
  405. }];
  406. }
  407. - (void)clearAllDeliveredNotifications {
  408. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  409. [center removeAllDeliveredNotifications];
  410. }
  411. - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification{
  412. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(jumpNotificationSettingPage) userInfo:nil repeats:YES];
  413. }
  414. @end