firebase - Wear OS 2 上的 Nativescript
问题描述
我在 Wear OS2 上使用 NativeScript。
我刚刚使用了 NS HelloWorld(打字稿非框架)并添加了 Firebase 插件以从通知中获取简单文本并将其显示在文本框中。
一切正常,除非应用程序从后台恢复,在这种情况下 UI 不会呈现文本更改。
调试时,我看到通知有效负载出现在我的打字稿页面实例中,没有错误……但是 UI 没有呈现它。
如果我在手机上运行相同的应用程序,所有工作都按预期工作,也会从后台恢复。相同的代码,没有一行差异。
我想知道 NativeScript 是否支持 Wear OS...
对此有什么想法吗?
谢谢,法比奥。
一些代码...
//主页面.ts
export function navigatingTo(args: EventData) {
//here Firebase is already init, all right...
(<Page>args.object).bindingContext = (new ViewModel).init();
}
//视图模型.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 and comes back to life
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);
}
}
}
//主页面.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>
解决方案
推荐阅读
- python - 删除 csv 文件的第二行并使用 Python 修改列
- django - 如何正确地对 Django 中间件进行单元测试
- javascript - 将未压缩的 scss 或 css 导入 js 文件时出现空样式标签
- javascript - 从 html 字符串获取列值 - Javascript
- scala - Scala Refined size 上的模式匹配
- python - 无法在 android 上的 pygame 中打开图像
- python-3.x - 如何使用python在每行文件中的值分隔符之前和之后修剪前导和尾随空格
- python - 如何在 Python 中与线程并行运行两个函数?
- powershell - 如何向查询添加另一个查询
- django - 相当于 reverse() 的 Django 通道