我在离子2应用程序中使用推送通知,代码如下。
import { Push, PushToken } from '@ionic/cloud-angular';
@Component({...})
export MyPage {
constructor(public platform: Platform, public menu: MenuController, public push: Push){
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
if (this.push) {
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t);
}).then((t: PushToken) => {
console.log('Token saved:', t.token);
window.localStorage.setItem("deviceToken", t.token);
});
this.push.rx.notification()
.subscribe((msg) => {
alert(msg.title + ': ' + msg.text);
console.log('notification msg', msg);
});
}
}
}
}
当我在设备上运行时它工作正常。但由于在构造函数
中注入了 Push ,我做离子服务它会产生以下误差error_handler.js:53 TypeError: platform.toLowerCase is not a function
at Insights.normalizeDevicePlatform (http://localhost:8100/build/main.js:70460:25)
at Insights.markActive (http://localhost:8100/build/main.js:70450:33)
at Insights.checkActivity (http://localhost:8100/build/main.js:70439:22)
at http://localhost:8100/build/main.js:70415:27
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9723)
at Object.onInvokeTask (http://localhost:8100/build/main.js:41825:37)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9659)
at e.runTask (http://localhost:8100/build/polyfills.js:3:7083)
at invoke (http://localhost:8100/build/polyfills.js:3:10836)
at e.args.(anonymous function) (http://localhost:8100/build/polyfills.js:2:30123)
ErrorHandler.handleError @ error_handler.js:53
任何帮助都是适当的
答案 0 :(得分:2)
检查class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('auction');
$rootNode
->children()
->scalarNode('path')->defaultValue(__DIR__ . '../web/images/tmp/')->end()
->scalarNode('miao')->defaultValue(__DIR__ . '../web/images/pmt/')->end()
->arrayNode('stock')
->children()
->scalarNode('pain')->defaultValue(__DIR__ . '../web/images/mpt/')->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
内的"@ionic/cloud-angular":"^ 0.9.0"
文件中是否有package.json
行。
如果是,请将其切换为dependencies
,保存文件并在项目根文件夹中运行^0.9.1
。这应该将npm install
更新为@ionic/cloud-angular
及其0.9.1
依赖关系更新为@ionic/cloud
。
然后运行0.15.1
它应该可以。
答案 1 :(得分:1)
在执行cordova操作之前,您应该检查cordova对象是否存在。
由于浏览器不是移动设备,因此在服务上不存在
initializeApp() {
this.platform.ready().then(() => {
if(!(<any>window).cordova) return;
...the native code you want to execute...
});
}