简体   繁体   English

流星-如何检测应用程序是否已打开?

[英]Meteor - How can I detect if an app has been opened?

I'm running a Meteor app on IOS and I'd like to reset the badge number to 0 when the app is opened. 我正在IOS上运行Meteor应用程序,我想在打开应用程序时将徽章编号重置为0。 My logic is to set the badge to zero whenever the app is opened, and increment it until it is opened again. 我的逻辑是在每次打开应用程序时将标志设置为零,然后将其递增直到再次打开。 How can I see if an app was pressed/opened? 如何查看是否已按下/打开某个应用程序? Meteor.startup doesn't seem to work. Meteor.startup似乎不起作用。 Is there some method called when the app is opened? 打开应用程序时是否调用了某些方法?

https://github.com/raix/push https://github.com/raix/push

In your AppDelegate.m : 在您的AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // set badge to 0

You could put a script in a template onCreated section, eg 您可以将脚本放在onCreated部分的模板中,例如

Template.example.onCreated(function(){
    //run your function here
});

Or put it in a template helper if you rely on reactive data. 或者,如果您依赖反应性数据,则将其放在模板帮助器中。

This seems late, but for future reference: You don't need to increment/decrement badge count manually. 这似乎很晚,但是供以后参考:您不需要手动增加/减少徽章计数。 Just add the properties badge and clearBadge in your client side Push Configuration on Meteor.startup like this: 只需在客户端Meteor.startup上的“推送配置”中添加属性badgeclearBadge ,如下所示:

Meteor.startup(() => {
    Push.Configure({
      ios: {
        alert: true,
        badge: true,
        sound: true,
        clearBadge: true
      }
    })
});

This will increment your badgeCount as soon as a notification arrives and will set the count to 0 when the user opens the app. 通知到达后,这将使您的badgeCount递增,并在用户打开应用程序时将计数设置为0。

For more detailed info, please follow this https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md 有关更多详细信息,请遵循此https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM