This is a NativeScript plugin that uses Apple WatchConnectivity to pass and receive data to a companion WatchOS app.
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.
npm i nativescript-watchos-connector
npm i nativescript-watchos-connector@1.0.11
NativeScript Angular
app.module.ts
:TypeScript
import { WatchOSConnector } from 'nativescript-watchos-connector'
@NgModule({
bootstrap: [AppComponent],
imports: [],
providers: [ WatchOSConnector ],
declarations: [ AppComponent ],
schemas: [ NO_ERRORS_SCHEMA ]
})
TypeScript
import { WatchOSConnector } from 'nativescript-watchos-connector'
TypeScript
constructor(
private _watchOSConnector: WatchOSConnector
) {}
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
checks if the device can support a WCSession, if so a WCSession will be created.
TypeScript
this.watchOSConnector.createWCSession()
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
}
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()
Returns the value as a NSNumber with int
TypeScript
this.watchOSConnector.convertInt(2319)
Returns the value as a NSNumber with double
TypeScript
this.watchOSConnector.convertDouble(42.957194)
Returns the value as a NSNumber with float
TypeScript
this.watchOSConnector.convertFloat(882.152)
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)
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