RCTPushNotificationManager.mm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTPushNotificationManager.h>
  8. #import <UserNotifications/UserNotifications.h>
  9. #import <FBReactNativeSpec/FBReactNativeSpec.h>
  10. #import <React/RCTBridge.h>
  11. #import <React/RCTConvert.h>
  12. #import <React/RCTEventDispatcher.h>
  13. #import <React/RCTUtils.h>
  14. #import "RCTPushNotificationPlugins.h"
  15. NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived";
  16. static NSString *const kLocalNotificationReceived = @"LocalNotificationReceived";
  17. static NSString *const kRemoteNotificationsRegistered = @"RemoteNotificationsRegistered";
  18. static NSString *const kRemoteNotificationRegistrationFailed = @"RemoteNotificationRegistrationFailed";
  19. static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";
  20. #if !TARGET_OS_TV
  21. @implementation RCTConvert (NSCalendarUnit)
  22. RCT_ENUM_CONVERTER(NSCalendarUnit,
  23. (@{
  24. @"year": @(NSCalendarUnitYear),
  25. @"month": @(NSCalendarUnitMonth),
  26. @"week": @(NSCalendarUnitWeekOfYear),
  27. @"day": @(NSCalendarUnitDay),
  28. @"hour": @(NSCalendarUnitHour),
  29. @"minute": @(NSCalendarUnitMinute)
  30. }),
  31. 0,
  32. integerValue)
  33. @end
  34. @interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
  35. @property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks;
  36. @end
  37. @implementation RCTConvert (UILocalNotification)
  38. + (UILocalNotification *)UILocalNotification:(id)json
  39. {
  40. NSDictionary<NSString *, id> *details = [self NSDictionary:json];
  41. BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
  42. UILocalNotification *notification = [UILocalNotification new];
  43. notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
  44. notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
  45. notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
  46. notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
  47. notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
  48. notification.category = [RCTConvert NSString:details[@"category"]];
  49. notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
  50. if (details[@"applicationIconBadgeNumber"]) {
  51. notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]];
  52. }
  53. if (!isSilent) {
  54. notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
  55. }
  56. return notification;
  57. }
  58. RCT_ENUM_CONVERTER(UIBackgroundFetchResult, (@{
  59. @"UIBackgroundFetchResultNewData": @(UIBackgroundFetchResultNewData),
  60. @"UIBackgroundFetchResultNoData": @(UIBackgroundFetchResultNoData),
  61. @"UIBackgroundFetchResultFailed": @(UIBackgroundFetchResultFailed),
  62. }), UIBackgroundFetchResultNoData, integerValue)
  63. @end
  64. #else
  65. @interface RCTPushNotificationManager () <NativePushNotificationManagerIOS>
  66. @end
  67. #endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
  68. @implementation RCTPushNotificationManager
  69. #if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
  70. static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
  71. {
  72. NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
  73. if (notification.fireDate) {
  74. NSDateFormatter *formatter = [NSDateFormatter new];
  75. [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
  76. NSString *fireDateString = [formatter stringFromDate:notification.fireDate];
  77. formattedLocalNotification[@"fireDate"] = fireDateString;
  78. }
  79. formattedLocalNotification[@"alertAction"] = RCTNullIfNil(notification.alertAction);
  80. formattedLocalNotification[@"alertBody"] = RCTNullIfNil(notification.alertBody);
  81. formattedLocalNotification[@"applicationIconBadgeNumber"] = @(notification.applicationIconBadgeNumber);
  82. formattedLocalNotification[@"category"] = RCTNullIfNil(notification.category);
  83. formattedLocalNotification[@"soundName"] = RCTNullIfNil(notification.soundName);
  84. formattedLocalNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(notification.userInfo));
  85. formattedLocalNotification[@"remote"] = @NO;
  86. return formattedLocalNotification;
  87. }
  88. API_AVAILABLE(ios(10.0))
  89. static NSDictionary *RCTFormatUNNotification(UNNotification *notification)
  90. {
  91. NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
  92. UNNotificationContent *content = notification.request.content;
  93. formattedNotification[@"identifier"] = notification.request.identifier;
  94. if (notification.date) {
  95. NSDateFormatter *formatter = [NSDateFormatter new];
  96. [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
  97. NSString *dateString = [formatter stringFromDate:notification.date];
  98. formattedNotification[@"date"] = dateString;
  99. }
  100. formattedNotification[@"title"] = RCTNullIfNil(content.title);
  101. formattedNotification[@"body"] = RCTNullIfNil(content.body);
  102. formattedNotification[@"category"] = RCTNullIfNil(content.categoryIdentifier);
  103. formattedNotification[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
  104. formattedNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
  105. return formattedNotification;
  106. }
  107. #endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
  108. RCT_EXPORT_MODULE()
  109. - (dispatch_queue_t)methodQueue
  110. {
  111. return dispatch_get_main_queue();
  112. }
  113. #if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
  114. - (void)startObserving
  115. {
  116. [[NSNotificationCenter defaultCenter] addObserver:self
  117. selector:@selector(handleLocalNotificationReceived:)
  118. name:kLocalNotificationReceived
  119. object:nil];
  120. [[NSNotificationCenter defaultCenter] addObserver:self
  121. selector:@selector(handleRemoteNotificationReceived:)
  122. name:RCTRemoteNotificationReceived
  123. object:nil];
  124. [[NSNotificationCenter defaultCenter] addObserver:self
  125. selector:@selector(handleRemoteNotificationsRegistered:)
  126. name:kRemoteNotificationsRegistered
  127. object:nil];
  128. [[NSNotificationCenter defaultCenter] addObserver:self
  129. selector:@selector(handleRemoteNotificationRegistrationError:)
  130. name:kRemoteNotificationRegistrationFailed
  131. object:nil];
  132. }
  133. - (void)stopObserving
  134. {
  135. [[NSNotificationCenter defaultCenter] removeObserver:self];
  136. }
  137. - (NSArray<NSString *> *)supportedEvents
  138. {
  139. return @[@"localNotificationReceived",
  140. @"remoteNotificationReceived",
  141. @"remoteNotificationsRegistered",
  142. @"remoteNotificationRegistrationError"];
  143. }
  144. + (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
  145. {
  146. }
  147. + (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  148. {
  149. NSMutableString *hexString = [NSMutableString string];
  150. NSUInteger deviceTokenLength = deviceToken.length;
  151. const unsigned char *bytes = reinterpret_cast<const unsigned char *>(deviceToken.bytes);
  152. for (NSUInteger i = 0; i < deviceTokenLength; i++) {
  153. [hexString appendFormat:@"%02x", bytes[i]];
  154. }
  155. [[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationsRegistered
  156. object:self
  157. userInfo:@{@"deviceToken" : [hexString copy]}];
  158. }
  159. + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  160. {
  161. [[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationRegistrationFailed
  162. object:self
  163. userInfo:@{@"error": error}];
  164. }
  165. + (void)didReceiveRemoteNotification:(NSDictionary *)notification
  166. {
  167. NSDictionary *userInfo = @{@"notification": notification};
  168. [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
  169. object:self
  170. userInfo:userInfo];
  171. }
  172. + (void)didReceiveRemoteNotification:(NSDictionary *)notification
  173. fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler
  174. {
  175. NSDictionary *userInfo = @{@"notification": notification, @"completionHandler": completionHandler};
  176. [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
  177. object:self
  178. userInfo:userInfo];
  179. }
  180. + (void)didReceiveLocalNotification:(UILocalNotification *)notification
  181. {
  182. [[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
  183. object:self
  184. userInfo:RCTFormatLocalNotification(notification)];
  185. }
  186. - (void)handleLocalNotificationReceived:(NSNotification *)notification
  187. {
  188. [self sendEventWithName:@"localNotificationReceived" body:notification.userInfo];
  189. }
  190. - (void)handleRemoteNotificationReceived:(NSNotification *)notification
  191. {
  192. NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:notification.userInfo[@"notification"]];
  193. RCTRemoteNotificationCallback completionHandler = notification.userInfo[@"completionHandler"];
  194. NSString *notificationId = [[NSUUID UUID] UUIDString];
  195. remoteNotification[@"notificationId"] = notificationId;
  196. remoteNotification[@"remote"] = @YES;
  197. if (completionHandler) {
  198. if (!self.remoteNotificationCallbacks) {
  199. // Lazy initialization
  200. self.remoteNotificationCallbacks = [NSMutableDictionary dictionary];
  201. }
  202. self.remoteNotificationCallbacks[notificationId] = completionHandler;
  203. }
  204. [self sendEventWithName:@"remoteNotificationReceived" body:remoteNotification];
  205. }
  206. - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
  207. {
  208. [self sendEventWithName:@"remoteNotificationsRegistered" body:notification.userInfo];
  209. }
  210. - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
  211. {
  212. NSError *error = notification.userInfo[@"error"];
  213. NSDictionary *errorDetails = @{
  214. @"message": error.localizedDescription,
  215. @"code": @(error.code),
  216. @"details": error.userInfo,
  217. };
  218. [self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
  219. }
  220. RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(NSString *)fetchResult) {
  221. UIBackgroundFetchResult result = [RCTConvert UIBackgroundFetchResult:fetchResult];
  222. RCTRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
  223. if (!completionHandler) {
  224. RCTLogError(@"There is no completion handler with notification id: %@", notificationId);
  225. return;
  226. }
  227. completionHandler(result);
  228. [self.remoteNotificationCallbacks removeObjectForKey:notificationId];
  229. }
  230. /**
  231. * Update the application icon badge number on the home screen
  232. */
  233. RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(double)number)
  234. {
  235. RCTSharedApplication().applicationIconBadgeNumber = number;
  236. }
  237. /**
  238. * Get the current application icon badge number on the home screen
  239. */
  240. RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback)
  241. {
  242. callback(@[@(RCTSharedApplication().applicationIconBadgeNumber)]);
  243. }
  244. RCT_EXPORT_METHOD(requestPermissions:(JS::NativePushNotificationManagerIOS::SpecRequestPermissionsPermission &)permissions
  245. resolve:(RCTPromiseResolveBlock)resolve
  246. reject:(RCTPromiseRejectBlock)reject)
  247. {
  248. if (RCTRunningInAppExtension()) {
  249. reject(kErrorUnableToRequestPermissions, nil, RCTErrorWithMessage(@"Requesting push notifications is currently unavailable in an app extension"));
  250. return;
  251. }
  252. // Add a listener to make sure that startObserving has been called
  253. [self addListener:@"remoteNotificationsRegistered"];
  254. UIUserNotificationType types = UIUserNotificationTypeNone;
  255. if (permissions.alert()) {
  256. types |= UIUserNotificationTypeAlert;
  257. }
  258. if (permissions.badge()) {
  259. types |= UIUserNotificationTypeBadge;
  260. }
  261. if (permissions.sound()) {
  262. types |= UIUserNotificationTypeSound;
  263. }
  264. [UNUserNotificationCenter.currentNotificationCenter
  265. requestAuthorizationWithOptions:types
  266. completionHandler:^(BOOL granted, NSError *_Nullable error) {
  267. if (error != NULL) {
  268. reject(@"-1", @"Error - Push authorization request failed.", error);
  269. } else {
  270. [RCTSharedApplication() registerForRemoteNotifications];
  271. [UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  272. resolve(RCTPromiseResolveValueForUNNotificationSettings(settings));
  273. }];
  274. }
  275. }];
  276. }
  277. RCT_EXPORT_METHOD(abandonPermissions)
  278. {
  279. [RCTSharedApplication() unregisterForRemoteNotifications];
  280. }
  281. RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
  282. {
  283. if (RCTRunningInAppExtension()) {
  284. callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO)]);
  285. return;
  286. }
  287. [UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  288. callback(@[RCTPromiseResolveValueForUNNotificationSettings(settings)]);
  289. }];
  290. }
  291. static inline NSDictionary *RCTPromiseResolveValueForUNNotificationSettings(UNNotificationSettings* _Nonnull settings) {
  292. return RCTSettingsDictForUNNotificationSettings(settings.alertSetting == UNNotificationSettingEnabled,
  293. settings.badgeSetting == UNNotificationSettingEnabled,
  294. settings.soundSetting == UNNotificationSettingEnabled);
  295. }
  296. static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound) {
  297. return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound)};
  298. }
  299. RCT_EXPORT_METHOD(presentLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
  300. {
  301. NSMutableDictionary *notificationDict = [NSMutableDictionary new];
  302. notificationDict[@"alertTitle"] = notification.alertTitle();
  303. notificationDict[@"alertBody"] = notification.alertBody();
  304. notificationDict[@"alertAction"] = notification.alertAction();
  305. notificationDict[@"userInfo"] = notification.userInfo();
  306. notificationDict[@"category"] = notification.category();
  307. notificationDict[@"repeatInterval"] = notification.repeatInterval();
  308. if (notification.fireDate()) {
  309. notificationDict[@"fireDate"] = @(*notification.fireDate());
  310. }
  311. if (notification.applicationIconBadgeNumber()) {
  312. notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
  313. }
  314. if (notification.isSilent()) {
  315. notificationDict[@"isSilent"] = @(*notification.isSilent());
  316. }
  317. [RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]];
  318. }
  319. RCT_EXPORT_METHOD(scheduleLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
  320. {
  321. NSMutableDictionary *notificationDict = [NSMutableDictionary new];
  322. notificationDict[@"alertTitle"] = notification.alertTitle();
  323. notificationDict[@"alertBody"] = notification.alertBody();
  324. notificationDict[@"alertAction"] = notification.alertAction();
  325. notificationDict[@"userInfo"] = notification.userInfo();
  326. notificationDict[@"category"] = notification.category();
  327. notificationDict[@"repeatInterval"] = notification.repeatInterval();
  328. if (notification.fireDate()) {
  329. notificationDict[@"fireDate"] = @(*notification.fireDate());
  330. }
  331. if (notification.applicationIconBadgeNumber()) {
  332. notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
  333. }
  334. if (notification.isSilent()) {
  335. notificationDict[@"isSilent"] = @(*notification.isSilent());
  336. }
  337. [RCTSharedApplication() scheduleLocalNotification:[RCTConvert UILocalNotification:notificationDict]];
  338. }
  339. RCT_EXPORT_METHOD(cancelAllLocalNotifications)
  340. {
  341. [RCTSharedApplication() cancelAllLocalNotifications];
  342. }
  343. RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userInfo)
  344. {
  345. for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
  346. __block BOOL matchesAll = YES;
  347. NSDictionary<NSString *, id> *notificationInfo = notification.userInfo;
  348. // Note: we do this with a loop instead of just `isEqualToDictionary:`
  349. // because we only require that all specified userInfo values match the
  350. // notificationInfo values - notificationInfo may contain additional values
  351. // which we don't care about.
  352. [userInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
  353. if (![notificationInfo[key] isEqual:obj]) {
  354. matchesAll = NO;
  355. *stop = YES;
  356. }
  357. }];
  358. if (matchesAll) {
  359. [RCTSharedApplication() cancelLocalNotification:notification];
  360. }
  361. }
  362. }
  363. RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
  364. reject:(__unused RCTPromiseRejectBlock)reject)
  365. {
  366. NSMutableDictionary<NSString *, id> *initialNotification =
  367. [self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
  368. UILocalNotification *initialLocalNotification =
  369. self.bridge.launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
  370. if (initialNotification) {
  371. initialNotification[@"remote"] = @YES;
  372. resolve(initialNotification);
  373. } else if (initialLocalNotification) {
  374. resolve(RCTFormatLocalNotification(initialLocalNotification));
  375. } else {
  376. resolve((id)kCFNull);
  377. }
  378. }
  379. RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callback)
  380. {
  381. NSArray<UILocalNotification *> *scheduledLocalNotifications = RCTSharedApplication().scheduledLocalNotifications;
  382. NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
  383. for (UILocalNotification *notification in scheduledLocalNotifications) {
  384. [formattedScheduledLocalNotifications addObject:RCTFormatLocalNotification(notification)];
  385. }
  386. callback(@[formattedScheduledLocalNotifications]);
  387. }
  388. RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
  389. {
  390. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  391. [center removeAllDeliveredNotifications];
  392. }
  393. RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray<NSString *> *)identifiers)
  394. {
  395. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  396. [center removeDeliveredNotificationsWithIdentifiers:identifiers];
  397. }
  398. RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback)
  399. {
  400. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  401. [center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *_Nonnull notifications) {
  402. NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
  403. for (UNNotification *notification in notifications) {
  404. [formattedNotifications addObject:RCTFormatUNNotification(notification)];
  405. }
  406. callback(@[formattedNotifications]);
  407. }];
  408. }
  409. #else //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
  410. RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(NSString *)fetchResult)
  411. {
  412. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  413. }
  414. RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(double)number)
  415. {
  416. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  417. }
  418. RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback)
  419. {
  420. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  421. }
  422. RCT_EXPORT_METHOD(requestPermissions:(JS::NativePushNotificationManagerIOS::SpecRequestPermissionsPermission &)permissions
  423. resolve:(RCTPromiseResolveBlock)resolve
  424. reject:(RCTPromiseRejectBlock)reject)
  425. {
  426. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  427. }
  428. RCT_EXPORT_METHOD(abandonPermissions)
  429. {
  430. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  431. }
  432. RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
  433. {
  434. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  435. }
  436. RCT_EXPORT_METHOD(presentLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
  437. {
  438. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  439. }
  440. RCT_EXPORT_METHOD(scheduleLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
  441. {
  442. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  443. }
  444. RCT_EXPORT_METHOD(cancelAllLocalNotifications)
  445. {
  446. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  447. }
  448. RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userInfo)
  449. {
  450. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  451. }
  452. RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
  453. reject:(__unused RCTPromiseRejectBlock)reject)
  454. {
  455. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  456. }
  457. RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callback)
  458. {
  459. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  460. }
  461. RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
  462. {
  463. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  464. }
  465. RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray<NSString *> *)identifiers)
  466. {
  467. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  468. }
  469. RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback)
  470. {
  471. RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
  472. }
  473. - (NSArray<NSString *> *)supportedEvents
  474. {
  475. return @[];
  476. }
  477. #endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
  478. - (std::shared_ptr<facebook::react::TurboModule>)
  479. getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
  480. nativeInvoker:(std::shared_ptr<facebook::react::CallInvoker>)nativeInvoker
  481. perfLogger:(id<RCTTurboModulePerformanceLogger>)perfLogger
  482. {
  483. return std::make_shared<facebook::react::NativePushNotificationManagerIOSSpecJSI>(self, jsInvoker, nativeInvoker, perfLogger);
  484. }
  485. @end
  486. Class RCTPushNotificationManagerCls(void) {
  487. return RCTPushNotificationManager.class;
  488. }