0

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.

2
  • What happens if you use Linking.openURL('whatsapp://');? Do you get any console errors when using Linking? Commented Nov 7, 2017 at 8:54
  • I've tried and nothing happens Commented Nov 7, 2017 at 11:21

2 Answers 2

1

Finally, in IOS is Linking.openUR("whatsapp://app") The word APP was what I was looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Thanks for comment. I have a doubt, I don't know where to create this file . I know nothing of Objetive C or swift. In the doc does not say where to create the file neither. Excuse my english.
You can create in IOS folder of your react-nativeproject. And details info is available in the docs for native modules.
There’s no need for a custom native module here, the Linking API already offers openURL and canOpenURL: facebook.github.io/react-native/docs/linking.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.