我在Wear OS2上使用NativeScript玩。
我刚刚使用了NS HelloWorld(非框架打字机),并添加了Firebase插件,以从通知中获取简单文本并将其显示在文本框中。
没关系,除非应用程序从后台恢复,在这种情况下,UI不会呈现文本更改。
调试,我看到通知有效载荷即将到达我的打字稿页面实例,没有错误...但是UI不会呈现它。
[如果我在手机上运行相同的应用程序,则所有工作都可以正常进行,并且也会在后台恢复。相同的代码,没有一行差异。
我想知道NativeScript是否支持Wear OS ...
对此有任何想法吗?
谢谢法比奥。
某些代码...
// main-page.ts
export function navigatingTo(args: EventData) {
//here Firebase is already init, all right...
(<Page>args.object).bindingContext = (new ViewModel).init();
}
// view-model.ts
import { Observable } from "tns-core-modules/data/observable";
import { NotificationService } from "./notification-service";
export class ViewModel extends Observable {
private _message: string = "Waiting message...";
init(): ViewModel {
//this callback is always invoked as expected
//also when the app is killed
NotificationService.onMessage = (firebaseMessage: any) => {
const text = firebaseMessage['text'] || firebaseMessage['data']['text'];
console.log('text' + text);
this.message = text; //that's okay, see setter below
}
return this;
}
get message(): string {
return this._message;
}
set message(value: string) {
if (this._message !== value) {
this._message = value;
//to this point the UI should update... BUT
//it works only IF the app is in foreground
//AND was never killed/backgrounded before.
//(bug on wear-os only)
this.notifyPropertyChange("message", value);
}
}
}
// main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<StackLayout class="p-20">
<Label text="{{ message }}" class="h2 text-center" textWrap="true" />
</StackLayout>
</Page>
我不知道答案,但是我对此也很好奇。尽管Wear OS是Android的变体,但我怀疑由于嵌入式可穿戴设备的优化而可能存在细微差别,这需要在NativeScript使用的本机组件/代码中加以考虑。我工作的公司与互联健身世界有关,所以我对有助于简化那里的应用程序/集成开发的任何框架/技术都非常感兴趣。对于Android TV,Android for Cars等问题,我也很想知道相同的答案。