Reputation: 3150
I am trying to open for example, What'sApp from my own React-Native App. I have reach to do this in Android with react-native-send-intent (SendIntentAndroid) but it only works in Android. I would like to do the same in IOS. Linking does not work for me and I don't know why.
Upvotes: 0
Views: 1822
Reputation: 3150
Finally, in IOS is Linking.openUR("whatsapp://app") The word APP was what I was looking for.
Upvotes: 1
Reputation: 851
If you want to share some thing from your app to other apps then you can do so by Share
module of react native.
docs for this module is available here.
And is you want to open other apps like whatsapp,or gmail or mail app, etc. then you can do so by implementing an native-module in IOS as.
#import "RCTBridgeModule.h"
#ifndef SampleNativeModule_h
#define SampleNativeModule_h
#endif /* SampleNativeModule_h */
@interface SampleNativeModule_h : NSObject <RCTBridgeModule>
@end
the above file is SampleNativeModule.h
#import "SampleNativeModule.h"
#import "RCTLog.h"
@import UIKit;
@implementation SampleNativeModule
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(openGmail)
{
NSURL* mailURL = [NSURL URLWithString:@"message://"];
NSURL* gmailURL = [NSURL URLWithString:@"googlegmail://"];
NSURL* appStoreURL = [NSURL URLWithString:@"itms://itunes.apple.com/us/app/googlegmail"];
if([[UIApplication sharedApplication] canOpenURL:gmailURL]){
[[UIApplication sharedApplication] openURL:gmailURL];
}else if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
[[UIApplication sharedApplication] openURL:mailURL];
}else{
[[UIApplication sharedApplication] openURL:appStoreURL];
}
}
@end
the above file is SampleNativeModule.m
which is native module file and you can can this as
import {NativeModules} from 'react-native'
const SampleNativeModule = NativeModules.SampleNativeModule;
// ........
SampleNativeModule.openGmail();
above i implemented method to open gmail app in IOS, but you can do for whatsapp and other app, by passing URL to your native module and open the corresponding app.
Upvotes: 0