当前位置: 首页 > 软件库 > 手机/移动开发 > >

nativescript-watchos-connector

授权协议 Apache-2.0 License
开发语言 JavaScript TypeScript
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 宰父衡
操作系统 iOS
开源组织
适用人群 未知
 软件概览

nativescript-watchos-connector

This is a NativeScript plugin that uses Apple WatchConnectivity to pass and receive data to a companion WatchOS app.

Prerequisites / Requirements

Before using this plugin, make sure you have followed the NativeScript blog post on Developing a watchOS Extension For Your NativeScript App and iOS WatchOS Applications.

Installation NativeScript 7

npm i nativescript-watchos-connector

Installation prior to NativeScript 7:

npm i nativescript-watchos-connector@1.0.11

Usage

NativeScript Angular

  1. For this plugin to work you must first add the nativescript-watchos-connector as a provider in your app.module.ts:

TypeScript

import  {  WatchOSConnector  }  from  'nativescript-watchos-connector'

@NgModule({
	bootstrap: [AppComponent],
	imports: [],
	providers: [ WatchOSConnector ],
	declarations: [ AppComponent ],
	schemas: [ NO_ERRORS_SCHEMA ]
})
  1. Import the nativescript-watchos-connector plugin:

TypeScript

import  {  WatchOSConnector  }  from  'nativescript-watchos-connector'
  1. Create an instance of the import in the constructor:

TypeScript

constructor(
	private _watchOSConnector: WatchOSConnector
) {}

Plugin Overview

This is a list of all currently available functions and a brief description of their usage within this plugin.

Function Description
createWCSession() Creates a WCSession
watchOSChecker() Checks if the user is on iOS, has an Apple Watch paired and the WatchOS app is installed
checkActivation() Checks if the WCSession is active (if not, session will be activated)
convertInt(value) Return value as Obj-C int
convertDouble(value) Return value as Obj-C double
convertFloat(value) Return value as Obj-C float
sendObjectToWatch('objectKey', object) Send the data to the companion WatchOS App using ApplicationContext

createWCSession()

createWCSession checks if the device can support a WCSession, if so a WCSession will be created.

TypeScript

this.watchOSConnector.createWCSession()

watchOSChecker()

Use watchOSChecker instead of isIOS when working with passing data to the Apple Watch. This checks if the user is on iOS, has an Apple Watch paired and the WatchOS app is installed (returns boolean)

TypeScript

if (this.watchOSConnector.watchOSChecker()) {
// Only run if WatchOS app is avalaible
}

checkActivation()

Checks if the WCSession is active, if not this will activate the current session. This is called in sendObject() to ensure there is an active session.

TypeScript

this.watchOSConnector.checkActivation()

convertInt(value)

Returns the value as a NSNumber with int

TypeScript

this.watchOSConnector.convertInt(2319)

convertDouble(value)

Returns the value as a NSNumber with double

TypeScript

this.watchOSConnector.convertDouble(42.957194)

convertFloat(value)

Returns the value as a NSNumber with float

TypeScript

this.watchOSConnector.convertFloat(882.152)

sendObjectToWatch(objectKey, object)

Sends the data to the companion WatchOS app using updateApplicationContext. You need to pass in a key for the object and an object of Objective-C valid values.

TypeScript

let intValue =  this.watchOSConnector.convertInt(4)
let doubleValue =  this.watchOSConnector.convertDouble(45.1)

let numberObject =  {
	convertedInt: intValue,
	convertedDouble: doubleValue
}

this.watchOSConnector.sendObject('numberObjectKey', numberObject)

v2.0.0 Release

  1. Updated to be compatible with NativeScript 7

Future Releases

  • Add images to README
  • Create a demo app

Contributors

License

Apache License Version 2.0, January 2004

 相关资料
  • watchOS 是 Apple Watch 的操作系统,由苹果公司开发,是以iOS操作系统为基础,两者之间有许多相似的功能。watchOS在2015年4月24日与苹果手表同时推出。苹果手表是唯一运行watchOS的装置。API称为WatchKit。 watchOS的主画面是由许多圆形的应用程序图示组成,画面可借由旋转苹果手表侧边的数位表冠(Digital Crown)来放大和缩小。不同的动作指令透

  • 问题内容: 简短:我不知道从CMSensorRecorder中获取一个后,如何从CMSensorDataList中提取CMRecordedAccelerometerData。苹果尚未提供任何文档。 也许有人对我有暗示?;) 好的,这里解决了这个问题:Swift中的NSFastEnumeration 借助Swift 3.0,它变为: 问题答案:

  • NativeScript 可以使用 Javascript,CSS, XML 创建真正的 Native 跨平台应用,支持 iOS Android,NativeScript 将您的跨平台代码翻译成目标平台的代码。 UI 使用 XML 描述,CSS 样式,在编译时将 UI 转化成本地原生代码,最终得到正在的 Native 原生应用。 Telerik 公开了用于创建安卓、iOS和Windows Unive

  • NativeScript Command-Line Interface The NativeScript CLI lets you create, build, and deploy NativeScript-based apps on iOS and Android devices. Get it using: npm install -g nativescript What is Native

  • NativeScript-Snackbar �� �� �� NativeScript plugin for Material Design SnackBar component. Installation: NativeScript 7+:tns plugin add @nstudio/nativescript-snackbar NativeScript version prior to 7:t

  • Nativescript-Ripple This plugin aims to bring a native (or close to native) ripple implementation on Android and iOS. The android version uses a RippleDrawable and conserves the previous background, a