GithubHelp home page GithubHelp logo

hjumeau / react-native-sms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tkporter/react-native-sms

0.0 2.0 0.0 24.04 MB

SMS sender with callbacks for iOS and Android

Java 77.32% Objective-C 18.99% JavaScript 3.69%

react-native-sms's Introduction

#react-native-sms

##SendSMS Use this component to send an SMS with a callback (completed/cancelled/error). Works for iOS and Android! Working as of RN 0.33.0

UPDATES:

Now supports 0.33.0-- keep in mind this could pose problems with older versions of RN

##How to install

  1. npm install react-native-sms --save

##Getting things set up

The compiler needs to know how to find your sweet new module! (Make sure rnpm is installed via npm install rnpm -g)

rnpm link react-native-sms

###Additional Android Setup Just a few quick & easy things you need to set up in order to get SendSMS up and running!

  1. Navigate to your MainActivity.java (MyApp/android/app/src/main/java/some/other/directories/MainActivity.java)

At the top of the file

import com.tkporter.sendsms.SendSMSPackage

Inside MainActivity (place entire function if it's not there already)

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	//probably some other stuff here
	SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data);
}

Then head to your [MyApp]Application.java (MyApp/android/app/src/main/java/so/many/dirs/MyAppApplication.java)

Make sure import com.tkporter.sendsms.SendSMSPackage; is there

Then head down to getPackages(), it has to look similar to this

protected List<ReactPackage> getPackages() {
	//some variables

	return Arrays.<ReactPackage>asList(
		//probably some items like `new BlahPackage(),`
		//just add into the list (don't forget commas!):
		SendSMSPackage.getInstance()
	);
}

Navigate to your AndroidManifest.xml (at MyApp/android/app/src/main/AndroidManifest.xml), and add this near the top with the other permssions

<uses-permission android:name="android.permission.READ_SMS" />

Ensure your launchMode for .MainActivity is

android:launchMode="singleTask"

##Using the module

Once everything is all setup, it's pretty simple:

SendSMS.send(myOptionsObject, callback);

###Object Properties

body (String, optional)

The text that shows by default when the SMS is initiated

recipients (Array (strings), optional)

Provides the phone number recipients to show by default

successTypes (Array (strings), Andriod only, required)

An array of types that would trigger a "completed" response when using android

Possible values:

'all' | 'inbox' | 'sent' | 'draft' | 'outbox' | 'failed' | 'queued'

##Example:

import SendSMS from 'react-native-sms'

//some stuff

someFunction() {

	SendSMS.send({
		body: 'The default body of the SMS!',
		recipients: ['0123456789', '9876543210'],
		successTypes: ['sent', 'queued']
	}, (completed, cancelled, error) => {

		console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);

	});
}

##Troubleshooting:

Having errors with import statements on Android? Something happened with linking

Go to your settings.gradle (in MyApp/android/settings.gradle) and add:

include ':react-native-sms'
project(':react-native-sms').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sms/android')

Then go to MyApp/android/app/build.gradle and add inside dependencies { }:

compile project(':react-native-sms')

react-native-sms's People

Contributors

tkporter avatar newxiaofeng avatar hjumeau avatar adrianzghibarta avatar kfiroo avatar rodrigopivi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.