Skip to content

Commit

Permalink
Add openURL method to sharedInstance.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkir committed Nov 14, 2017
1 parent 02bf0c9 commit 123d0e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,19 @@ export NODE_BINARY=node
../bin/react-native-xcode.sh
```

# Open container app
Steps needed to open the host application from the share extension.
1) Allow your app to be opened via URL Scheme - [Learn more](https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e)
2) In xcode, select share extension and go to Build Settings and set **Require Only App-Extension-Safe API** to `NO`.

Then you can open your app from the share extension by calling openURL:

```
import ShareExtension from 'react-native-share-extension';
ShareExtension.openURL('sample://example/url');
```

# Troubleshooting on iOS devices

Using the iOS Simulator and remote react-native debugger to develop the extension can hide issues that won't occur until testing on device. If you're experiencing issues running the extension on iOS devices, examine the Xcode console or device log for any obvious errors. If the Xcode console isn't receiving console output, ensure that the OS_ACTIVITY_MODE=disable environment var isn't enabled for the active scheme (see https://github.com/facebook/react-native/issues/10027). OS_ACTIVITY_MODE will hide device logging in the Xcode console, so its use is only advisable for iOS Simulator. For release mode, in order to view console output and see all output in the syslog, uncomment the `RCTSetLogThreshold(RCTLogLevelInfo - 1);` statement in your MyShareEx class.
Expand Down
8 changes: 8 additions & 0 deletions ios/ReactNativeShareExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ - (void)viewDidLoad {



RCT_EXPORT_METHOD(openURL:(NSString *)url) {
UIApplication *application = [UIApplication sharedApplication];
NSURL *urlToOpen = [NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[application openURL:urlToOpen options:@{} completionHandler: nil];
}



RCT_REMAP_METHOD(data,
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import { NativeModules } from 'react-native'
// NativeModules.ShareExtension.close()
export default {
data: () => NativeModules.ReactNativeShareExtension.data(),
close: () => NativeModules.ReactNativeShareExtension.close()
close: () => NativeModules.ReactNativeShareExtension.close(),
openURL: (url) => NativeModules.ReactNativeShareExtension.openURL(url),
}

0 comments on commit 123d0e4

Please sign in to comment.