0.0.6 • Published 5 years ago

react-native-openanything v0.0.6

Weekly downloads
512
License
MIT
Repository
github
Last release
5 years ago

react-native-openanything

Open anything in your react-native app.

Supports call, email, text (sms), iMessage (iOS only), Map, PDF, etc.

Installation

React Native >= 0.49

npm install react-native-openanything

General Guide

This library is promise based and each method returns a promise.

    import {Call} from 'react-native-openanything';

    Call('+155555555555').catch(err => console.error(err));

Available Methods

Call a number from your app!

Call(phone, prompt = false)
PropDescriptionDefault
phoneA string that represents the phone number to call.Required
promptIf set to true, it will ask the user for permission to call. Only iOSfalse

Send an email from your app!

Email(to = false, subject = false, body = false, cc = false, bcc = false)
ParameterDescriptionDefault
toA value that indicates the recipient e-mail. Can either be string for single recipient or an array for multiple recipients.false optional
subjectA string for the subject for the e-mail.false optional
bodyA string for the body message for the e-mail.false optional
ccSame as to however the recipient(s) will be designated for the cc field.false optional
bccSame as to however the recipient(s) will be designated for the bcc field.false optional

Note: The default email application will be open even if no parameter is set.


Send an text (sms) from your app!

Text(phone, message = false, autoEncode = true)
ParameterDescriptionDefault
phoneA string that represents the phone number to call.Required
messageA string for the message.false optional
autoEncodeIf set to true, the method will auto encode the message.true optional

By default this method tries to properly encode the message however in same cases that might not work. If you have trouble just set the autoEncode parameter to false.

Note: If message is not a string, this method will open the default text client regardless.


Open any URL from your app!

Web(url)
ParameterDescriptionDefault
urlA string that represents the url.Required

Displays a map from your app!

Map(address)
ParameterDescriptionDefault
addressA string that represents the address.Required

Note: You can either provide an string or an array with latitude and longitude to this method.


Opens a YouTube Video

Youtube(video)
ParameterDescriptionDefault
videoA string that contains the Youtube video id.Required

Opens Twitter

Twitter(user)
ParameterDescriptionDefault
userA string that contains the Twitter User Id that should be open.Required

Opens Facebook

Facebook(user)
ParameterDescriptionDefault
userA string that contains the Facebook User Id that should be open.Required

Opens Instagram User, Media, Camera, App, Location and Tag

Instagram(user)
ParameterDescriptionDefault
userA string that contains the Instagram User Id that should be open.Required
InstagramMedia(media)
ParameterDescriptionDefault
userA string that contains the Instagram Media Id that should be open.Required
InstagramLocation(location)
ParameterDescriptionDefault
userA string that contains the Instagram Location Id that should be open.Required
InstagramTag(tag)
ParameterDescriptionDefault
userA string that contains the Instagram Tag Id that should be open.Required
InstagramApp()

Opens the Instagram App.

InstagramCamera()

Opens the Instagram Camera.


Only iOS Launch Facetime

Facetime(target, audioOnly = false)
ParameterDescriptionDefault
targetA string that representing a phone number or a username.Required
audioOnlyA boolean value indicating if facetime is an audio callfalse optional

Low level methods

Note: You should only use these methods if you know what you doing.


Supported - checks if a deep linking URL is supported on the current device.

Supported(url)
ParameterDescriptionDefault
urlThe url to check.Required

Open - opens an deep linking URL.

Open(url)
ParameterDescriptionDefault
urlThe url to open.Required

Launch - Combines Supported and Open

Launch(url)
ParameterDescriptionDefault
urlThe url to verify and open.Required

Issues and how to resolve them

App is not allowed to query scheme

On iOS you might run into this issue. The reaon is that you have to explicit add the requesting query schemes into the pinfo.list variable LSApplicationQueriesSchemes.

e.g. for Facebook you would add fb. Please refer to the example list below for the correct query scheme string:

TargetQuery Scheme
Facebookfb
Instagraminstagram
Twittertwitter
LinkedInlinkedin
WhatsAppwhatsapp

Examples

You can either import specific modules:

import { Call, Text, Web, Map, EMail } from 'react-native-openanything';

...

render() {

	<View>
    	<Button onPress={() => Call('+12105551234')}>
        	<Text>Call</Text>
        </Button>
        <Button onPress={() => Text('+12105551234', 'Can you please call me!')}>
        	<Text>Text</Text>
        </Button>
    </View>
}

or import all modules as wildcard:

import * as OpenAnything from 'react-native-openanything';

...

render() {

	<View>
    	<Button onPress={() => OpenAnything.Call('+12105551234')}>
        	<Text>Call</Text>
        </Button>
        <Button onPress={() => OpenAnything.Call('+12105551234', 'Can you please call me!')}>
        	<Text>Text</Text>
        </Button>
        <Button onPress={() => OpenAnything.Email('someone@google.com')}>
        	<Text>E-Mail</Text>
        </Button>
        <Button onPress={() => OpenAnything.Web('http://www.google.com')}>
        	<Text>Google Homepage</Text>
        </Button>
        <Button onPress={() => OpenAnything.Map('Google')}>
        	<Text>Google HQ</Text>
        </Button>
    </View>
}