Native node bindings to iOS functionality (vibrate, acceleromoter, geoservices, etc.)
This module offers native node binding to Apple iOS functionality, meant for node
running on an Apple iDevice. It exposes low-level functionality of the device, like
vibrate, sending SMS messages, displaying pop-up user notifications, simulating the
home and lock buttons, and a lot more planned!
Considering the fact that most jailbroken devices won't have a GCC toolchain set up on their device, this repo includes a pre-built version of the module that hopefully will work on the majority of devices.
I'm always looking for ideas for additional APIs to add. So if you can think of any functionality that you want exposed to JavaScript that's missing from the API below, then please don't hesitate to open an Issue requesting it!
Creates and displays a pop-up "notification" onto the iDevice. The optional callback
function will be called after the notification has been dismissed (through user interaction
or otherwise cancelled).
The most recent call to this function will be the active notification. That is, if there's already an active notification, and this function is called, then the newly created notification will take precedence over any existing notifications. So if you want to display a series of notifications, it's better invoke the next one in the previous notification's callback.
iOS.createNotification({
header: "Title",
message: "Enter your name..."
}, function(err, response) {
if (err) throw err;
console.log(response);
});
The options
Object accepts the following parameters:
header
- A String that will be used as the header of the notification. Defaults tonull
.message
- A String that will be used as the message body of the notification. Defaults tonull
.defaultButton
- The text of the default (primary) button. Defaults to'OK'
. To disable the default button (notification without any buttons), explicity passnull
here.alternateButton
- The text of the secondary (alternate) button. Defaults tonull
(no second button).otherButton
- The text of the third (other) button. Defaults tonull
(no third button).timeout
- The timeout in seconds of the notification. Defaults to0
for no timeout.
There's one global AddressBook
instance that you may use to interact with the
contents of your iDevice's central Address Book database. It's also possible to
modify the Address Book by adding, editing or removing contacts or groups.
// The singleton AddressBook namespace:
iOS.AddressBook;
Asynchronously retrieves an Array of "Contact" instances from the Address Book database that match the given filter. If no filter is given, then ALL contacts that are currently in the Address Book will be retrieved.
iOS.AddressBook.getContacts(function(err, contacts) {
if (err) // Something went wrong
console.log(contacts);
// [ {
// firstName: 'John',
// lastName: 'Doe',
// numbers: { Mobile: '(555) 555-5555' } },
// ...
// ]
});
Vibrates the iDevice shortly. This is the same as when a text message or email arrives, etc. On devices that don't vibrate, this function does nothing (no error is thrown).
Returns an Object containing properties from the current UIDevice. An example:
{ model: 'iPhone',
localizedModel: 'iPhone',
name: 'Nathan Rajlich’s iPhone',
systemName: 'iPhone OS',
systemVersion: '4.3.1',
uniqueIdentifier: 'f1dfb3fa9f73fc9ffef4fcf3f61fff6f05ff1afb' }
Sends an SMS with the specified message
String to the specified number
. Examples:
iOS.sendSMS('5555555555', 'this is a text message!');
iOS.sendSMS('555-555-5555', 'another text message!');
iOS.sendSMS('(555) 555-5555', 'and one more?!');
iOS.sendSMS(5555555555, 'you may just use a Number as well');
Locks the screen of the iDevice. Same effect as pressing the top "Lock" button.
Quits the currently visible application, going straight to the Home screen. On a device with multitasking support, the app will still be running in the process list. Same effect as pressing the "Home" button.