npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unitehere/nativescript-phone

v3.1.0

Published

NativeScript plugin to use the device phone and SMS features for Android and iOS

Downloads

18

Readme

npm npm

NativeScript Phone

NativeScript plugin to use the device phone and SMS features for Android and iOS

Native Info

Installation

Install the plugin using the NativeScript CLI

tns plugin add @unitehere/nativescript-phone

Breaking Change with 3.x.x

Version 3.x.x and later uses an event system to dispatch events for the handling of success, failure, errors for the SMS and Dial methods. See the snippets below for the correct usage of the event emitter system.

Video Tutorial

egghead plugin lesson @ https://egghead.io/lessons/javascript-using-the-device-phone-and-sms-with-nativescript

Android

To dial the phone without user interaction on Android your app must request permission to dial. The following must be in your app's AndroidManifest.xml.

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

IOS

You must add the following line to your project's Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
   <string>tel</string>
   <string>telprompt</string>
</array>

Usage

To use the phone module you must first require() it from your project's node_modules directory:

var phone = require('@unitehere/nativescript-phone');

After you have a reference to the module you can then call the available methods.

Methods

dial: initiate a phone call

Parameters
  • telNum: Phone number to dial.
  • prompt: Boolean to enable OS specific confirmation before dialing.

For example, the code below dials the number without showing the device specific confirmation prompt:

// my-page.js
var phone = require('@unitehere/nativescript-phone');
phone.dial('212-555-1234', false);

sms: open the OS specific SMS app

Parameters
  • smsNum: SMS number or numbers to use.
  • messageText: String to send.

For example, the code below opens the sms app for the provided number:

Send to one number (provided for backwards compatibility)

// my-page.js

import {
  NSPhoneEventEmitter,
  sms,
  dial,
  requestCallPermission,
  SMSEvents,
  DialEvents
} from '@unitehere/nativescript-phone';

NSPhoneEventEmitter.on(SMSEvents.FAILED, args => {
  console.log('FAILED', args.data);
});

NSPhoneEventEmitter.on(SMSEvents.SUCCESS, args => {
  console.log('SMS Successful');
});

NSPhoneEventEmitter.on(SMSEvents.CANCELLED, args => {
  console.log('SMS Cancelled');
});

NSPhoneEventEmitter.on(SMSEvents.ERROR, args => {
  console.log('SMS ERROR', args.data);
});

NSPhoneEventEmitter.on(SMSEvents.UNKNOWN, args => {
  console.log('SMS UNKNOWN', args.data);
});

sms(['212-555-1234'], 'testing');

Send to multiple numbers

import { sms } from '@unitehere/nativescript-phone';
// Use the event system to listen for failure, success, cancelled, error events

sms(['212-555-1234', '212-555-1245'], 'My Message');

requestCallPermission: Request Android Call_Phone Permission

Parameters

  • explanation: The explanation text if the user denies permission twice (nullable). If you attempt to use dial("122929912", false) to not prompt on android 6.0, nothing will happen unless permission has been approved before. When this method is executed, a check for permissions happens, and a promise is returned. If the user refuse it, you can handle it via the catch method of promise. If it accepts you can dial in the thenmethod. You should so "wrap" your dial method inside of the requestCallPermission() method (see following example).

TypeScript example

import {
  NSPhoneEventEmitter,
  sms,
  dial,
  requestCallPermission,
  SMSEvents,
  DialEvents
} from '@unitehere/nativescript-phone';

NSPhoneEventEmitter.on(SMSEvents.ERROR, args => {
  console.log('SMS ERROR', args.data);
});

NSPhoneEventEmitter.on(SMSEvents.UNKNOWN, args => {
  console.log('SMS UNKNOWN', args.data);
});

/// Dial a phone number.
function callHome() {
  const phoneNumber = '415-123-4567';
  requestCallPermission(
    'You should accept the permission to be able to make a direct phone call.'
  )
    .then(() => dial(phoneNumber, false))
    .catch(() => dial(phoneNumber, true));
}

// Text a number (or multiple numbers)
function messageParents() {
  sms(['212-555-1234', '212-555-0987'], 'Text till your fingers bleed');
}