New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

watchconnectivity

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchconnectivity

Simple plugin that establishes iOS Watch Connectivity session with Watch OS 2 and helps exchange of messages between an iPhone hybrid application and its iWatch application

latest
Source
npmnpm
Version
1.1.6
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Cordova Watch Connectivity Plugin

Simple plugin that establishes iOS Watch Connectivity session with Watch OS 2 and helps exchange of messages between an iPhone hybrid application and its iWatch application.

Installation

With cordova-cli

If you are using cordova-cli, install with:

cordova plugin add https://github.com/DVenkatesh/cordova-plugin-watchconnectivity.git

With plugman

With a plain plugman, you should be able to install with something like:

plugman --platform <ios> --project <directory> --plugin https://github.com/DVenkatesh/cordova-plugin-watchconnectivity.git

Use from Javascript

Edit www/js/index.js and add the following code inside onDeviceReady

    var didReceiveMessage = function(message){
        var obj = JSON.parse(message);
        alert(obj.message);
    }
    var msgSendSuccess = function() {
        alert("Message send success");
    }
    var failure = function() {
        alert("Error");
    }
    var success = function() {
        sswc.messageReceiver(didReceiveMessage, failure);
        sswc.sendMessage("Message from phone", msgSendSuccess, failure);
    }
    sswc.init(success, failure);

Use from iWatch extension

Objective-C

// Setup and activate session in awakeWithContext or willActivate
if ([WCSession isSupported]) {
    WCSession *session = [WCSession defaultSession];
    session.delegate = self;
    [session activateSession];
}
// Implement didReceiveMessage WatchConnectivity handler/callback to receive incoming messages
- (void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *, id> *)message replyHandler:(void(^)(NSDictionary<NSString *, id> *replyMessage))replyHandler {
    NSString *message = [message objectForKey:@"message"];
    NSLog(@"%@",message);
    [self sendMessage:@"Message from iWatch"];
}
// Send message
- (void)sendMessage:(NSString*)message {
    NSDictionary *messageDictionary = [[NSDictionary alloc] initWithObjects:@[message] forKeys:@[@"message"]];
    [[WCSession defaultSession] sendMessage:messageDictionary
                               replyHandler:^(NSDictionary *reply) {
                                   NSLog(@"Send message success");
                               }
                               errorHandler:^(NSError *error) {
                                   NSLog(@"Send message failed");
                               }
     ];
}

Swift

// Setup and activate session in awakeWithContext or willActivate
if WCSession.isSupported() {
    let session = WCSession.defaultSession()
    session.delegate = self
    session.activateSession()
}
// Implement didReceiveMessage WatchConnectivity handler/callback to receive incoming messages
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
    let message = message["message"] as? String
    print(message)
    self.sendMessage("Message from iWatch")
}
// Send message
func sendMessage:(message: String) -> Void{
    let message = ["message": message]
    WCSession.defaultSession()!.sendMessage(["message": message], 
                                replyHandler: { (response) -> Void in
                                    print("Send message success")
                                }, errorHandler: { (error) -> Void in
                                    print("Send message failed")
                                })
     
}

Credits

Written by Venkatesh D and Vagish M M

More Info

TODO: The plugin is very simple and short without much error handling. This is developed for an immediate need and shall be upgraded to support other platforms with error handling and improved design.

For more information on setting up Cordova see the documentation

For more info on plugins see the Plugin Development Guide

Keywords

Watch

FAQs

Package last updated on 29 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts