2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-24 15:31:11 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-24 15:31:11 +03:00
|
|
|
*/
|
|
|
|
|
CocoaPods frameworks compatibility: Step 2 (#25619)
Summary:
This is my proposal for fixing `use_frameworks!` compatibility without breaking all `<React/*>` imports I outlined in https://github.com/facebook/react-native/pull/25393#issuecomment-508457700. If accepted, it will fix https://github.com/facebook/react-native/issues/25349.
It builds on the changes I made in https://github.com/facebook/react-native/pull/25496 by ensuring each podspec has a unique value for `header_dir` so that framework imports do not conflict. Every podspec which should be included in the `<React/*>` namespace now includes it's headers from `React-Core.podspec`.
The following pods can still be imported with `<React/*>` and so should not have breaking changes: `React-ART`,`React-DevSupport`, `React-CoreModules`, `React-RCTActionSheet`, `React-RCTAnimation`, `React-RCTBlob`, `React-RCTImage`, `React-RCTLinking`, `React-RCTNetwork`, `React-RCTPushNotification`, `React-RCTSettings`, `React-RCTText`, `React-RCTSettings`, `React-RCTVibration`, `React-RCTWebSocket` .
There are still a few breaking changes which I hope will be acceptable:
- `React-Core.podspec` has been moved to the root of the project. Any `Podfile` that references it will need to update the path.
- ~~`React-turbomodule-core`'s headers now live under `<turbomodule/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-turbomodulesamples`'s headers now live under `<turbomodulesamples/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-TypeSaferty`'s headers now live under `<TypeSafety/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511040967.
- ~~`React-jscallinvoker`'s headers now live under `<jscallinvoker/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- Each podspec now uses `s.static_framework = true`. This means that a minimum of CocoaPods 1.5 ([released in April 2018](http://blog.cocoapods.org/CocoaPods-1.5.0/)) is now required. This is needed so that the ` __has_include` conditions can still work when frameworks are enabled.
Still to do:
- ~~Including `React-turbomodule-core` with `use_frameworks!` enabled causes the C++ import failures we saw in https://github.com/facebook/react-native/issues/25349. I'm sure it will be possible to fix this but I need to dig deeper (perhaps a custom modulemap would be needed).~~ Addressed by https://github.com/facebook/react-native/pull/25619/commits/33573511f02f3502a28bad48e085e9a4b8608302.
- I haven't got Fabric working yet. I wonder if it would be acceptable to move Fabric out of the `<React/*>` namespace since it is new? �
## Changelog
[iOS] [Fixed] - Fixed compatibility with CocoaPods frameworks.
Pull Request resolved: https://github.com/facebook/react-native/pull/25619
Test Plan:
### FB
```
buck build catalyst
```
### Sample Project
Everything should work exactly as before, where `use_frameworks!` is not in `Podfile`s. I have a branch on my [sample project](https://github.com/jtreanor/react-native-cocoapods-frameworks) here which has `use_frameworks!` in its `Podfile` to demonstrate this is fixed.
You can see that it works with these steps:
1. `git clone git@github.com:jtreanor/react-native-cocoapods-frameworks.git`
2. `git checkout fix-frameworks-subspecs`
3. `cd ios && pod install`
4. `cd .. && react-native run-ios`
The sample app will build and run successfully. To see that it still works without frameworks, remove `use_frameworks!` from the `Podfile` and do steps 3 and 4 again.
### RNTesterPods
`RNTesterPodsPods` can now work with or without `use_frameworks!`.
1. Go to the `RNTester` directory and run `pod install`.
2. Run the tests in `RNTesterPods.xcworkspace` to see that everything still works fine.
3. Uncomment the `use_frameworks!` line at the top of `RNTester/Podfile` and run `pod install` again.
4. Run the tests again and see that it still works with frameworks enabled.
Reviewed By: PeteTheHeat
Differential Revision: D16465247
Pulled By: PeteTheHeat
fbshipit-source-id: cad837e9cced06d30cc5b372af1c65c7780b9e7a
2019-07-25 08:26:42 +03:00
|
|
|
#import <React/RCTPushNotificationManager.h>
|
2015-03-24 15:31:11 +03:00
|
|
|
|
2017-03-23 21:48:04 +03:00
|
|
|
#import <UserNotifications/UserNotifications.h>
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
2016-11-23 18:47:52 +03:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTEventDispatcher.h>
|
|
|
|
#import <React/RCTUtils.h>
|
2015-03-24 15:31:11 +03:00
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
#import "RCTPushNotificationPlugins.h"
|
|
|
|
|
2015-03-24 15:31:11 +03:00
|
|
|
NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived";
|
2016-06-04 02:14:44 +03:00
|
|
|
|
2017-07-25 14:40:19 +03:00
|
|
|
static NSString *const kLocalNotificationReceived = @"LocalNotificationReceived";
|
|
|
|
static NSString *const kRemoteNotificationsRegistered = @"RemoteNotificationsRegistered";
|
|
|
|
static NSString *const kRemoteNotificationRegistrationFailed = @"RemoteNotificationRegistrationFailed";
|
|
|
|
|
|
|
|
static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";
|
2016-06-04 02:14:44 +03:00
|
|
|
|
Enabling RCTWebSocket on UIKitForMac (macOS Catalyst) (#27469)
Summary:
In https://github.com/facebook/react-native/issues/25427, radex added initial support for running React Native projects on macOS via Catalyst. However, `RCTWebSocket` was disabled for that target because of some compilation issues. This meant that running projects via a connection to the packager wasn't possible: no live reload, and projects must be run in "Release" mode. It also meant making manual changes to Xcode projects deploying to macOS and scattering a number of conditional checks throughout the codebase.
In this change, I've implemented support for `RCTWebSocket` on the macOS target and re-enabled the affected features. Live reload and the inspector now work for macOS targets. Manual modifications of Xcode build settings are no longer necessary for react-native projects running on macOS.
![Screen Shot 2019-12-10 at 8 36 38 AM](https://user-images.githubusercontent.com/2771/70549905-ce7b0800-1b29-11ea-85c6-07bf09811ae2.png)
### Limitations
There's no binding which displays the developer menu (since there's no shake event on macOS). We'll probably want to add one, perhaps to the menu bar.
I've chosen not to commit the modifications to RNTester which enable macOS support, since that would imply more "official" support for this target than I suspect you all would like to convey. I'm happy to add those chunks if it would be helpful.
## Changelog
[iOS] [Added] - Added web socket support for macOS (Catalyst), enabling debug builds and live reload
Pull Request resolved: https://github.com/facebook/react-native/pull/27469
Test Plan:
* Open RNTester/RNTester.xcodeproj with Xcode 11.2.1, run it like a normal iOS app -- make sure it compiles and runs correctly (no regression)
* Select "My Mac" as device target, and run. You may need to configure a valid development team to make signing work.
* RNTester should run fine with no additional configuration. Modify a file in RNTester, note that live reload is now working.
* Test the developer inspector. To display the developer menu, you'll need to manually show it; here's an example diff which does that:
```
diff --git a/RNTester/js/RNTesterApp.ios.js b/RNTester/js/RNTesterApp.ios.js
index 8245a68d12..a447ad3b1b 100644
--- a/RNTester/js/RNTesterApp.ios.js
+++ b/RNTester/js/RNTesterApp.ios.js
@@ -19,6 +19,8 @@ const React = require('react');
const SnapshotViewIOS = require('./examples/Snapshot/SnapshotViewIOS.ios');
const URIActionMap = require('./utils/URIActionMap');
+import NativeDevMenu from '../../Libraries/NativeModules/specs/NativeDevMenu';
+
const {
AppRegistry,
AsyncStorage,
@@ -143,6 +145,7 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
UNSAFE_componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBack);
+ NativeDevMenu.show();
}
componentDidMount() {
```
Reviewed By: sammy-SC
Differential Revision: D18945861
Pulled By: hramos
fbshipit-source-id: edcf02c5803742c89a845a3e5d72bc7dacae839f
2019-12-18 03:50:24 +03:00
|
|
|
#if !TARGET_OS_TV
|
2016-10-11 17:39:48 +03:00
|
|
|
@implementation RCTConvert (NSCalendarUnit)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(NSCalendarUnit,
|
|
|
|
(@{
|
|
|
|
@"year": @(NSCalendarUnitYear),
|
|
|
|
@"month": @(NSCalendarUnitMonth),
|
|
|
|
@"week": @(NSCalendarUnitWeekOfYear),
|
|
|
|
@"day": @(NSCalendarUnitDay),
|
|
|
|
@"hour": @(NSCalendarUnitHour),
|
|
|
|
@"minute": @(NSCalendarUnitMinute)
|
|
|
|
}),
|
|
|
|
0,
|
|
|
|
integerValue)
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
|
2016-10-27 07:35:33 +03:00
|
|
|
@property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks;
|
|
|
|
@end
|
|
|
|
|
2015-07-14 19:07:24 +03:00
|
|
|
@implementation RCTConvert (UILocalNotification)
|
|
|
|
|
|
|
|
+ (UILocalNotification *)UILocalNotification:(id)json
|
|
|
|
{
|
2015-11-14 21:25:00 +03:00
|
|
|
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
|
2017-05-29 01:26:01 +03:00
|
|
|
BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
|
2015-08-17 17:35:34 +03:00
|
|
|
UILocalNotification *notification = [UILocalNotification new];
|
2017-08-07 06:16:04 +03:00
|
|
|
notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
|
2015-07-14 19:07:24 +03:00
|
|
|
notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
|
|
|
|
notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
|
2016-02-19 16:18:24 +03:00
|
|
|
notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
|
2016-02-09 16:45:23 +03:00
|
|
|
notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
|
2016-02-19 16:18:24 +03:00
|
|
|
notification.category = [RCTConvert NSString:details[@"category"]];
|
2016-10-11 17:39:48 +03:00
|
|
|
notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
|
2016-04-29 15:36:08 +03:00
|
|
|
if (details[@"applicationIconBadgeNumber"]) {
|
|
|
|
notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]];
|
|
|
|
}
|
2017-05-29 01:26:01 +03:00
|
|
|
if (!isSilent) {
|
|
|
|
notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
|
|
|
|
}
|
2015-07-14 19:07:24 +03:00
|
|
|
return notification;
|
|
|
|
}
|
|
|
|
|
2016-10-27 07:35:33 +03:00
|
|
|
RCT_ENUM_CONVERTER(UIBackgroundFetchResult, (@{
|
|
|
|
@"UIBackgroundFetchResultNewData": @(UIBackgroundFetchResultNewData),
|
|
|
|
@"UIBackgroundFetchResultNoData": @(UIBackgroundFetchResultNoData),
|
|
|
|
@"UIBackgroundFetchResultFailed": @(UIBackgroundFetchResultFailed),
|
|
|
|
}), UIBackgroundFetchResultNoData, integerValue)
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
@end
|
|
|
|
#else
|
|
|
|
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOS>
|
2015-07-14 19:07:24 +03:00
|
|
|
@end
|
2019-07-04 20:27:03 +03:00
|
|
|
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
|
2015-07-14 19:07:24 +03:00
|
|
|
|
2015-03-24 15:31:11 +03:00
|
|
|
@implementation RCTPushNotificationManager
|
|
|
|
|
2019-07-04 20:27:03 +03:00
|
|
|
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
|
2016-10-17 01:37:45 +03:00
|
|
|
|
2016-06-10 15:15:54 +03:00
|
|
|
static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
|
2016-06-06 19:18:59 +03:00
|
|
|
{
|
|
|
|
NSMutableDictionary *formattedLocalNotification = [NSMutableDictionary dictionary];
|
|
|
|
if (notification.fireDate) {
|
2016-06-10 15:15:54 +03:00
|
|
|
NSDateFormatter *formatter = [NSDateFormatter new];
|
2016-06-06 19:18:59 +03:00
|
|
|
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
|
|
|
|
NSString *fireDateString = [formatter stringFromDate:notification.fireDate];
|
|
|
|
formattedLocalNotification[@"fireDate"] = fireDateString;
|
|
|
|
}
|
|
|
|
formattedLocalNotification[@"alertAction"] = RCTNullIfNil(notification.alertAction);
|
|
|
|
formattedLocalNotification[@"alertBody"] = RCTNullIfNil(notification.alertBody);
|
|
|
|
formattedLocalNotification[@"applicationIconBadgeNumber"] = @(notification.applicationIconBadgeNumber);
|
|
|
|
formattedLocalNotification[@"category"] = RCTNullIfNil(notification.category);
|
|
|
|
formattedLocalNotification[@"soundName"] = RCTNullIfNil(notification.soundName);
|
|
|
|
formattedLocalNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(notification.userInfo));
|
2016-07-13 08:56:00 +03:00
|
|
|
formattedLocalNotification[@"remote"] = @NO;
|
2016-06-06 19:18:59 +03:00
|
|
|
return formattedLocalNotification;
|
|
|
|
}
|
|
|
|
|
2019-11-04 23:01:10 +03:00
|
|
|
API_AVAILABLE(ios(10.0))
|
2017-03-23 21:48:04 +03:00
|
|
|
static NSDictionary *RCTFormatUNNotification(UNNotification *notification)
|
|
|
|
{
|
|
|
|
NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary];
|
|
|
|
UNNotificationContent *content = notification.request.content;
|
|
|
|
|
|
|
|
formattedNotification[@"identifier"] = notification.request.identifier;
|
|
|
|
|
|
|
|
if (notification.date) {
|
|
|
|
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
|
|
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"];
|
|
|
|
NSString *dateString = [formatter stringFromDate:notification.date];
|
|
|
|
formattedNotification[@"date"] = dateString;
|
|
|
|
}
|
|
|
|
|
|
|
|
formattedNotification[@"title"] = RCTNullIfNil(content.title);
|
|
|
|
formattedNotification[@"body"] = RCTNullIfNil(content.body);
|
|
|
|
formattedNotification[@"category"] = RCTNullIfNil(content.categoryIdentifier);
|
|
|
|
formattedNotification[@"thread-id"] = RCTNullIfNil(content.threadIdentifier);
|
|
|
|
formattedNotification[@"userInfo"] = RCTNullIfNil(RCTJSONClean(content.userInfo));
|
|
|
|
|
|
|
|
return formattedNotification;
|
|
|
|
}
|
|
|
|
|
2019-07-04 20:27:03 +03:00
|
|
|
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
|
2016-10-17 01:37:45 +03:00
|
|
|
|
2015-04-08 15:42:43 +03:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2016-06-10 15:15:54 +03:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
|
|
|
return dispatch_get_main_queue();
|
|
|
|
}
|
|
|
|
|
2019-07-04 20:27:03 +03:00
|
|
|
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
|
2016-05-27 20:14:12 +03:00
|
|
|
- (void)startObserving
|
2016-05-04 17:06:09 +03:00
|
|
|
{
|
2016-02-09 16:45:23 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(handleLocalNotificationReceived:)
|
2017-07-25 14:40:19 +03:00
|
|
|
name:kLocalNotificationReceived
|
2016-02-09 16:45:23 +03:00
|
|
|
object:nil];
|
2015-11-25 14:09:00 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(handleRemoteNotificationReceived:)
|
|
|
|
name:RCTRemoteNotificationReceived
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(handleRemoteNotificationsRegistered:)
|
2017-07-25 14:40:19 +03:00
|
|
|
name:kRemoteNotificationsRegistered
|
2015-11-25 14:09:00 +03:00
|
|
|
object:nil];
|
2016-09-06 21:01:31 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(handleRemoteNotificationRegistrationError:)
|
2017-07-25 14:40:19 +03:00
|
|
|
name:kRemoteNotificationRegistrationFailed
|
2016-09-06 21:01:31 +03:00
|
|
|
object:nil];
|
2015-11-25 14:09:00 +03:00
|
|
|
}
|
|
|
|
|
2016-05-27 20:14:12 +03:00
|
|
|
- (void)stopObserving
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray<NSString *> *)supportedEvents
|
|
|
|
{
|
|
|
|
return @[@"localNotificationReceived",
|
|
|
|
@"remoteNotificationReceived",
|
2016-09-06 21:01:31 +03:00
|
|
|
@"remoteNotificationsRegistered",
|
|
|
|
@"remoteNotificationRegistrationError"];
|
2016-05-27 20:14:12 +03:00
|
|
|
}
|
|
|
|
|
2016-01-05 13:42:18 +03:00
|
|
|
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-05 13:42:18 +03:00
|
|
|
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
2015-06-04 00:11:20 +03:00
|
|
|
{
|
|
|
|
NSMutableString *hexString = [NSMutableString string];
|
2015-06-15 17:53:45 +03:00
|
|
|
NSUInteger deviceTokenLength = deviceToken.length;
|
2019-11-09 01:08:11 +03:00
|
|
|
const unsigned char *bytes = reinterpret_cast<const unsigned char *>(deviceToken.bytes);
|
2015-06-15 17:53:45 +03:00
|
|
|
for (NSUInteger i = 0; i < deviceTokenLength; i++) {
|
2015-06-04 00:11:20 +03:00
|
|
|
[hexString appendFormat:@"%02x", bytes[i]];
|
|
|
|
}
|
2017-07-25 14:40:19 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationsRegistered
|
2015-06-04 00:11:20 +03:00
|
|
|
object:self
|
2016-02-09 16:45:23 +03:00
|
|
|
userInfo:@{@"deviceToken" : [hexString copy]}];
|
2015-06-04 00:11:20 +03:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:01:31 +03:00
|
|
|
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
|
|
|
{
|
2017-07-25 14:40:19 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationRegistrationFailed
|
2016-09-06 21:01:31 +03:00
|
|
|
object:self
|
|
|
|
userInfo:@{@"error": error}];
|
|
|
|
}
|
|
|
|
|
2016-01-05 13:42:18 +03:00
|
|
|
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
2016-10-27 07:35:33 +03:00
|
|
|
NSDictionary *userInfo = @{@"notification": notification};
|
2015-03-24 15:31:11 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
|
|
|
|
object:self
|
2016-10-27 07:35:33 +03:00
|
|
|
userInfo:userInfo];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
|
|
|
|
fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler
|
|
|
|
{
|
|
|
|
NSDictionary *userInfo = @{@"notification": notification, @"completionHandler": completionHandler};
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
|
|
|
|
object:self
|
|
|
|
userInfo:userInfo];
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 16:45:23 +03:00
|
|
|
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification
|
|
|
|
{
|
2017-07-25 14:40:19 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
|
2016-02-09 16:45:23 +03:00
|
|
|
object:self
|
2016-06-10 15:15:54 +03:00
|
|
|
userInfo:RCTFormatLocalNotification(notification)];
|
2016-02-09 16:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleLocalNotificationReceived:(NSNotification *)notification
|
|
|
|
{
|
2016-05-27 20:14:12 +03:00
|
|
|
[self sendEventWithName:@"localNotificationReceived" body:notification.userInfo];
|
2016-02-09 16:45:23 +03:00
|
|
|
}
|
|
|
|
|
2015-03-24 15:31:11 +03:00
|
|
|
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
|
|
|
{
|
2016-10-27 07:35:33 +03:00
|
|
|
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:notification.userInfo[@"notification"]];
|
|
|
|
RCTRemoteNotificationCallback completionHandler = notification.userInfo[@"completionHandler"];
|
2016-11-23 18:47:52 +03:00
|
|
|
NSString *notificationId = [[NSUUID UUID] UUIDString];
|
2016-10-27 07:35:33 +03:00
|
|
|
remoteNotification[@"notificationId"] = notificationId;
|
|
|
|
remoteNotification[@"remote"] = @YES;
|
|
|
|
if (completionHandler) {
|
|
|
|
if (!self.remoteNotificationCallbacks) {
|
|
|
|
// Lazy initialization
|
|
|
|
self.remoteNotificationCallbacks = [NSMutableDictionary dictionary];
|
|
|
|
}
|
|
|
|
self.remoteNotificationCallbacks[notificationId] = completionHandler;
|
|
|
|
}
|
|
|
|
|
2016-11-14 22:24:07 +03:00
|
|
|
[self sendEventWithName:@"remoteNotificationReceived" body:remoteNotification];
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
2015-06-04 00:11:20 +03:00
|
|
|
- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
|
|
|
|
{
|
2016-05-27 20:14:12 +03:00
|
|
|
[self sendEventWithName:@"remoteNotificationsRegistered" body:notification.userInfo];
|
2015-06-04 00:11:20 +03:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:01:31 +03:00
|
|
|
- (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSError *error = notification.userInfo[@"error"];
|
|
|
|
NSDictionary *errorDetails = @{
|
|
|
|
@"message": error.localizedDescription,
|
|
|
|
@"code": @(error.code),
|
|
|
|
@"details": error.userInfo,
|
|
|
|
};
|
|
|
|
[self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
|
|
|
|
}
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(NSString *)fetchResult) {
|
|
|
|
UIBackgroundFetchResult result = [RCTConvert UIBackgroundFetchResult:fetchResult];
|
2016-10-27 07:35:33 +03:00
|
|
|
RCTRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
|
|
|
|
if (!completionHandler) {
|
2016-10-27 13:12:37 +03:00
|
|
|
RCTLogError(@"There is no completion handler with notification id: %@", notificationId);
|
2016-10-27 07:35:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
completionHandler(result);
|
|
|
|
[self.remoteNotificationCallbacks removeObjectForKey:notificationId];
|
|
|
|
}
|
|
|
|
|
2015-03-24 15:31:11 +03:00
|
|
|
/**
|
|
|
|
* Update the application icon badge number on the home screen
|
|
|
|
*/
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(double)number)
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
2015-09-22 20:43:56 +03:00
|
|
|
RCTSharedApplication().applicationIconBadgeNumber = number;
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current application icon badge number on the home screen
|
|
|
|
*/
|
2015-04-08 18:52:48 +03:00
|
|
|
RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback)
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
2016-02-09 16:45:23 +03:00
|
|
|
callback(@[@(RCTSharedApplication().applicationIconBadgeNumber)]);
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(requestPermissions:(JS::NativePushNotificationManagerIOS::SpecRequestPermissionsPermission &)permissions
|
|
|
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
|
|
reject:(RCTPromiseRejectBlock)reject)
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
2020-02-07 19:48:15 +03:00
|
|
|
if (RCTRunningInAppExtension()) {
|
|
|
|
reject(kErrorUnableToRequestPermissions, nil, RCTErrorWithMessage(@"Requesting push notifications is currently unavailable in an app extension"));
|
|
|
|
return;
|
|
|
|
}
|
2016-06-04 02:14:44 +03:00
|
|
|
|
2017-04-19 21:25:50 +03:00
|
|
|
// Add a listener to make sure that startObserving has been called
|
|
|
|
[self addListener:@"remoteNotificationsRegistered"];
|
2016-06-04 02:14:44 +03:00
|
|
|
|
2015-06-10 01:42:10 +03:00
|
|
|
UIUserNotificationType types = UIUserNotificationTypeNone;
|
2019-11-09 01:08:11 +03:00
|
|
|
|
|
|
|
if (permissions.alert()) {
|
|
|
|
types |= UIUserNotificationTypeAlert;
|
|
|
|
}
|
|
|
|
if (permissions.badge()) {
|
|
|
|
types |= UIUserNotificationTypeBadge;
|
|
|
|
}
|
|
|
|
if (permissions.sound()) {
|
|
|
|
types |= UIUserNotificationTypeSound;
|
2015-06-04 00:11:20 +03:00
|
|
|
}
|
2015-04-10 13:10:04 +03:00
|
|
|
|
2020-02-07 19:48:15 +03:00
|
|
|
[UNUserNotificationCenter.currentNotificationCenter
|
|
|
|
requestAuthorizationWithOptions:types
|
|
|
|
completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
|
|
|
if (error != NULL) {
|
|
|
|
reject(@"-1", @"Error - Push authorization request failed.", error);
|
|
|
|
} else {
|
|
|
|
[RCTSharedApplication() registerForRemoteNotifications];
|
|
|
|
[UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
|
|
|
resolve(RCTPromiseResolveValueForUNNotificationSettings(settings));
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}];
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
2015-06-15 22:14:23 +03:00
|
|
|
RCT_EXPORT_METHOD(abandonPermissions)
|
|
|
|
{
|
2015-09-22 20:43:56 +03:00
|
|
|
[RCTSharedApplication() unregisterForRemoteNotifications];
|
2015-06-15 22:14:23 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:52:48 +03:00
|
|
|
RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
|
2015-03-24 15:31:11 +03:00
|
|
|
{
|
2015-09-22 20:43:56 +03:00
|
|
|
if (RCTRunningInAppExtension()) {
|
2020-02-07 19:48:15 +03:00
|
|
|
callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO)]);
|
2015-09-22 20:43:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:48:15 +03:00
|
|
|
[UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
|
|
|
callback(@[RCTPromiseResolveValueForUNNotificationSettings(settings)]);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NSDictionary *RCTPromiseResolveValueForUNNotificationSettings(UNNotificationSettings* _Nonnull settings) {
|
|
|
|
return RCTSettingsDictForUNNotificationSettings(settings.alertSetting == UNNotificationSettingEnabled,
|
|
|
|
settings.badgeSetting == UNNotificationSettingEnabled,
|
|
|
|
settings.soundSetting == UNNotificationSettingEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound) {
|
|
|
|
return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound)};
|
2015-03-24 15:31:11 +03:00
|
|
|
}
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(presentLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
|
2015-07-14 19:07:24 +03:00
|
|
|
{
|
2019-11-09 01:08:11 +03:00
|
|
|
NSMutableDictionary *notificationDict = [NSMutableDictionary new];
|
|
|
|
notificationDict[@"alertTitle"] = notification.alertTitle();
|
|
|
|
notificationDict[@"alertBody"] = notification.alertBody();
|
|
|
|
notificationDict[@"alertAction"] = notification.alertAction();
|
|
|
|
notificationDict[@"userInfo"] = notification.userInfo();
|
|
|
|
notificationDict[@"category"] = notification.category();
|
|
|
|
notificationDict[@"repeatInterval"] = notification.repeatInterval();
|
|
|
|
if (notification.fireDate()) {
|
|
|
|
notificationDict[@"fireDate"] = @(*notification.fireDate());
|
|
|
|
}
|
|
|
|
if (notification.applicationIconBadgeNumber()) {
|
|
|
|
notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
|
|
|
|
}
|
|
|
|
if (notification.isSilent()) {
|
|
|
|
notificationDict[@"isSilent"] = @(*notification.isSilent());
|
|
|
|
}
|
|
|
|
[RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]];
|
2015-07-14 19:07:24 +03:00
|
|
|
}
|
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(scheduleLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
|
2015-07-14 19:07:24 +03:00
|
|
|
{
|
2019-11-09 01:08:11 +03:00
|
|
|
NSMutableDictionary *notificationDict = [NSMutableDictionary new];
|
|
|
|
notificationDict[@"alertTitle"] = notification.alertTitle();
|
|
|
|
notificationDict[@"alertBody"] = notification.alertBody();
|
|
|
|
notificationDict[@"alertAction"] = notification.alertAction();
|
|
|
|
notificationDict[@"userInfo"] = notification.userInfo();
|
|
|
|
notificationDict[@"category"] = notification.category();
|
|
|
|
notificationDict[@"repeatInterval"] = notification.repeatInterval();
|
|
|
|
if (notification.fireDate()) {
|
|
|
|
notificationDict[@"fireDate"] = @(*notification.fireDate());
|
|
|
|
}
|
|
|
|
if (notification.applicationIconBadgeNumber()) {
|
|
|
|
notificationDict[@"applicationIconBadgeNumber"] = @(*notification.applicationIconBadgeNumber());
|
|
|
|
}
|
|
|
|
if (notification.isSilent()) {
|
|
|
|
notificationDict[@"isSilent"] = @(*notification.isSilent());
|
|
|
|
}
|
|
|
|
[RCTSharedApplication() scheduleLocalNotification:[RCTConvert UILocalNotification:notificationDict]];
|
2015-07-14 19:07:24 +03:00
|
|
|
}
|
|
|
|
|
2015-10-16 20:39:38 +03:00
|
|
|
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
|
|
|
|
{
|
|
|
|
[RCTSharedApplication() cancelAllLocalNotifications];
|
|
|
|
}
|
|
|
|
|
2016-06-10 15:15:54 +03:00
|
|
|
RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userInfo)
|
2016-02-09 16:45:23 +03:00
|
|
|
{
|
2017-04-01 13:16:52 +03:00
|
|
|
for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
|
2016-02-09 16:45:23 +03:00
|
|
|
__block BOOL matchesAll = YES;
|
2016-06-10 15:15:54 +03:00
|
|
|
NSDictionary<NSString *, id> *notificationInfo = notification.userInfo;
|
|
|
|
// Note: we do this with a loop instead of just `isEqualToDictionary:`
|
|
|
|
// because we only require that all specified userInfo values match the
|
|
|
|
// notificationInfo values - notificationInfo may contain additional values
|
|
|
|
// which we don't care about.
|
2016-02-09 16:45:23 +03:00
|
|
|
[userInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
|
|
|
|
if (![notificationInfo[key] isEqual:obj]) {
|
|
|
|
matchesAll = NO;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
if (matchesAll) {
|
2017-04-01 13:16:52 +03:00
|
|
|
[RCTSharedApplication() cancelLocalNotification:notification];
|
2016-02-09 16:45:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 20:14:12 +03:00
|
|
|
RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
|
|
|
|
reject:(__unused RCTPromiseRejectBlock)reject)
|
|
|
|
{
|
2016-07-13 08:56:00 +03:00
|
|
|
NSMutableDictionary<NSString *, id> *initialNotification =
|
|
|
|
[self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
|
2016-06-10 15:15:54 +03:00
|
|
|
|
|
|
|
UILocalNotification *initialLocalNotification =
|
|
|
|
self.bridge.launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
|
|
|
|
|
|
|
|
if (initialNotification) {
|
2016-07-13 08:56:00 +03:00
|
|
|
initialNotification[@"remote"] = @YES;
|
|
|
|
resolve(initialNotification);
|
2016-06-10 15:15:54 +03:00
|
|
|
} else if (initialLocalNotification) {
|
|
|
|
resolve(RCTFormatLocalNotification(initialLocalNotification));
|
|
|
|
} else {
|
|
|
|
resolve((id)kCFNull);
|
|
|
|
}
|
2016-05-27 20:14:12 +03:00
|
|
|
}
|
|
|
|
|
2016-06-06 19:18:59 +03:00
|
|
|
RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
2017-04-01 13:16:52 +03:00
|
|
|
NSArray<UILocalNotification *> *scheduledLocalNotifications = RCTSharedApplication().scheduledLocalNotifications;
|
2016-06-10 15:15:54 +03:00
|
|
|
NSMutableArray<NSDictionary *> *formattedScheduledLocalNotifications = [NSMutableArray new];
|
2016-06-06 19:18:59 +03:00
|
|
|
for (UILocalNotification *notification in scheduledLocalNotifications) {
|
2016-06-10 15:15:54 +03:00
|
|
|
[formattedScheduledLocalNotifications addObject:RCTFormatLocalNotification(notification)];
|
2016-06-06 19:18:59 +03:00
|
|
|
}
|
|
|
|
callback(@[formattedScheduledLocalNotifications]);
|
|
|
|
}
|
|
|
|
|
2017-03-23 21:48:04 +03:00
|
|
|
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
|
|
|
|
{
|
2020-01-15 20:21:20 +03:00
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
[center removeAllDeliveredNotifications];
|
2017-03-23 21:48:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray<NSString *> *)identifiers)
|
|
|
|
{
|
2020-01-15 20:21:20 +03:00
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
[center removeDeliveredNotificationsWithIdentifiers:identifiers];
|
2017-03-23 21:48:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
2020-01-15 20:21:20 +03:00
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *_Nonnull notifications) {
|
|
|
|
NSMutableArray<NSDictionary *> *formattedNotifications = [NSMutableArray new];
|
2017-03-23 21:48:04 +03:00
|
|
|
|
2020-01-15 20:21:20 +03:00
|
|
|
for (UNNotification *notification in notifications) {
|
|
|
|
[formattedNotifications addObject:RCTFormatUNNotification(notification)];
|
|
|
|
}
|
|
|
|
callback(@[formattedNotifications]);
|
|
|
|
}];
|
2017-03-23 21:48:04 +03:00
|
|
|
}
|
|
|
|
|
2019-07-04 20:27:03 +03:00
|
|
|
#else //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
|
2017-03-24 00:58:20 +03:00
|
|
|
|
2019-11-09 01:08:11 +03:00
|
|
|
RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(NSString *)fetchResult)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(double)number)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(requestPermissions:(JS::NativePushNotificationManagerIOS::SpecRequestPermissionsPermission &)permissions
|
|
|
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
|
|
reject:(RCTPromiseRejectBlock)reject)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(abandonPermissions)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(presentLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(scheduleLocalNotification:(JS::NativePushNotificationManagerIOS::Notification &)notification)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(cancelLocalNotifications:(NSDictionary<NSString *, id> *)userInfo)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve
|
|
|
|
reject:(__unused RCTPromiseRejectBlock)reject)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray<NSString *> *)identifiers)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
|
|
|
|
}
|
|
|
|
|
2017-03-24 00:58:20 +03:00
|
|
|
- (NSArray<NSString *> *)supportedEvents
|
|
|
|
{
|
|
|
|
return @[];
|
|
|
|
}
|
|
|
|
|
2019-07-04 20:27:03 +03:00
|
|
|
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
|
2016-10-17 01:37:45 +03:00
|
|
|
|
Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams
Summary:
## Summary
Please check out D21035209.
## Changes
- Codemod all ObjC NativeModule `getTurboModuleWithJsInvoker:nativeInvoker:perfLogger` methods to `getTurboModule:(const ObjCTurboModule::Args)`
## Script
```
var withSpaces = (...args) => args.join('\s*')
var regexString = withSpaces(
'-',
'\(',
'std::shared_ptr',
'<',
'(?<turboModuleClass>(facebook::react::|react::|::|)TurboModule)',
'>',
'\)',
'getTurboModuleWithJsInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(?<fbNamespace>(facebook::react::|react::|::|))CallInvoker',
'>',
'\)',
'(?<jsInvokerInstance>[A-Za-z0-9]+)',
'nativeInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(facebook::react::|react::|::|)CallInvoker',
'>',
'\)',
'(?<nativeInvokerInstance>[A-Za-z0-9]+)',
'perfLogger',
':',
'\(',
'id',
'<',
'RCTTurboModulePerformanceLogger',
'>',
'\)',
'(?<perfLoggerInstance>[A-Za-z0-9]+)',
'{',
'return',
'std::make_shared',
'<',
'(?<specName>(facebook::react::|react::|::|)Native[%A-Za-z0-9]+SpecJSI)',
'>',
'\(',
'self',
',',
'\k<jsInvokerInstance>',
',',
'\k<nativeInvokerInstance>',
',',
'\k<perfLoggerInstance>',
'\)',
';',
'}',
)
var replaceString = `- (std::shared_ptr<$<turboModuleClass>>) getTurboModule:(const $<fbNamespace>ObjCTurboModule::InitParams &)params
{
return std::make_shared<$<specName>>(params);
}`
const exec = require('../lib/exec');
const abspath = require('../lib/abspath');
const relpath = require('../lib/relpath');
const readFile = (filename) => require('fs').readFileSync(filename, 'utf8');
const writeFile = (filename, content) => require('fs').writeFileSync(filename, content);
function main() {
const tmFiles = exec('cd ~/fbsource && xbgs -n 10000 -l getTurboModuleWithJsInvoker:').split('\n').filter(Boolean);
tmFiles
.filter((filename) => !filename.includes('microsoft-fork-of-react-native'))
.map(abspath)
.forEach((filename) => {
const source = readFile(filename);
const newSource = source.replace(new RegExp(regexString, 'g'), replaceString);
if (source == newSource) {
console.log(relpath(filename));
}
writeFile(filename, newSource);
});
}
if (!module.parent) {
main();
}
```
## Re-generating diff
```
> hg revert -r .^ --all
> node index.js # run script
```
Changelog: [iOS][Changed] - Make all ObjC NativeModules create TurboModules using ObjCTurboModule::Args
Reviewed By: PeteTheHeat
Differential Revision: D21036265
fbshipit-source-id: 404bcc548d1775ef23d793527606d02fe384a0a2
2020-04-17 03:23:39 +03:00
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
|
2019-11-09 01:08:11 +03:00
|
|
|
{
|
Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams
Summary:
## Summary
Please check out D21035209.
## Changes
- Codemod all ObjC NativeModule `getTurboModuleWithJsInvoker:nativeInvoker:perfLogger` methods to `getTurboModule:(const ObjCTurboModule::Args)`
## Script
```
var withSpaces = (...args) => args.join('\s*')
var regexString = withSpaces(
'-',
'\(',
'std::shared_ptr',
'<',
'(?<turboModuleClass>(facebook::react::|react::|::|)TurboModule)',
'>',
'\)',
'getTurboModuleWithJsInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(?<fbNamespace>(facebook::react::|react::|::|))CallInvoker',
'>',
'\)',
'(?<jsInvokerInstance>[A-Za-z0-9]+)',
'nativeInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(facebook::react::|react::|::|)CallInvoker',
'>',
'\)',
'(?<nativeInvokerInstance>[A-Za-z0-9]+)',
'perfLogger',
':',
'\(',
'id',
'<',
'RCTTurboModulePerformanceLogger',
'>',
'\)',
'(?<perfLoggerInstance>[A-Za-z0-9]+)',
'{',
'return',
'std::make_shared',
'<',
'(?<specName>(facebook::react::|react::|::|)Native[%A-Za-z0-9]+SpecJSI)',
'>',
'\(',
'self',
',',
'\k<jsInvokerInstance>',
',',
'\k<nativeInvokerInstance>',
',',
'\k<perfLoggerInstance>',
'\)',
';',
'}',
)
var replaceString = `- (std::shared_ptr<$<turboModuleClass>>) getTurboModule:(const $<fbNamespace>ObjCTurboModule::InitParams &)params
{
return std::make_shared<$<specName>>(params);
}`
const exec = require('../lib/exec');
const abspath = require('../lib/abspath');
const relpath = require('../lib/relpath');
const readFile = (filename) => require('fs').readFileSync(filename, 'utf8');
const writeFile = (filename, content) => require('fs').writeFileSync(filename, content);
function main() {
const tmFiles = exec('cd ~/fbsource && xbgs -n 10000 -l getTurboModuleWithJsInvoker:').split('\n').filter(Boolean);
tmFiles
.filter((filename) => !filename.includes('microsoft-fork-of-react-native'))
.map(abspath)
.forEach((filename) => {
const source = readFile(filename);
const newSource = source.replace(new RegExp(regexString, 'g'), replaceString);
if (source == newSource) {
console.log(relpath(filename));
}
writeFile(filename, newSource);
});
}
if (!module.parent) {
main();
}
```
## Re-generating diff
```
> hg revert -r .^ --all
> node index.js # run script
```
Changelog: [iOS][Changed] - Make all ObjC NativeModules create TurboModules using ObjCTurboModule::Args
Reviewed By: PeteTheHeat
Differential Revision: D21036265
fbshipit-source-id: 404bcc548d1775ef23d793527606d02fe384a0a2
2020-04-17 03:23:39 +03:00
|
|
|
return std::make_shared<facebook::react::NativePushNotificationManagerIOSSpecJSI>(params);
|
2019-11-09 01:08:11 +03:00
|
|
|
}
|
|
|
|
|
2015-03-24 15:31:11 +03:00
|
|
|
@end
|
2019-11-09 01:08:11 +03:00
|
|
|
|
|
|
|
Class RCTPushNotificationManagerCls(void) {
|
|
|
|
return RCTPushNotificationManager.class;
|
|
|
|
}
|