简体   繁体   English

iOS:无声推送触发本地通知的问题

[英]iOS:Issue with Silent Push triggering Local Notification

In my app I am using a daily silent push to trigger some calculations inside my app and based on the calculation result I am triggering a local notification. 在我的应用程序中,我使用每日静音推送来触发我的应用程序内的一些计算,并根据计算结果我触发本地通知。

Say for example: A daily goal. 比如说:每日目标。

Once the silent notification reaches my app, I trigger a background method to calculate the user data and compare whether his/ her data achieved a goal and if yes I trigger a local notification so that user can open the app and check. 一旦无声通知到达我的应用程序,我触发后台方法来计算用户数据并比较他/她的数据是否达到了目标,如果是,我触发本地通知,以便用户可以打开应用程序并检查。

It is not working consistently, sometimes I get it and sometimes don't. 它不是一贯的工作,有时我得到它,有时不做。 When I debugged, what I saw was that the execution get paused in between and execution gets resumed only if the user opens the app again or I trigger a silent push again. 当我调试时,我看到的是执行在两者之间暂停,只有当用户再次打开应用程序或我再次触发静默推送时,执行才会恢复。 Not sure why the background execution (the calculation) gets paused, and if I trigger a push or if i manually try to open the app, I can see the breakpoint appearing back and it continues from the place it was paused. 不确定为什么后台执行(计算)被暂停,如果我触发推送或者如果我手动尝试打开应用程序,我可以看到断点出现并且它从暂停的地方继续。

I am wondering whether it is because of some time limit?? 我想知道是否是因为一些时间限制?

UPDATE: 更新:

I am using UrbanAirshipSDK and they have some handlers overridden and I am using the below method to handle the notification. 我正在使用UrbanAirshipSDK,他们有一些处理程序被覆盖,我使用以下方法来处理通知。 This is written in the appdelegate and gets called when I get a notification when app is in background. 这是在appdelegate中编写的,当app在后台时收到通知时会被调用。

/**
 * Called when a push notification is received while the app is running in the background
 * for applications with the "remote-notification" background mode.  
 * Overridden by receivedBackgroundNotification:fetchCompletionHandler.
 *
 * @param notification The notification dictionary.
 */
- (void)receivedBackgroundNotification:(NSDictionary *)notification;

I first check for content-available in the payload and treat as silent and do the calculations. 我首先检查有效负载中的内容是否可用,并将其视为无声并进行计算。 This works fine intermittently but not consistently. 这可以间歇性地工作但不一致。 I am closing towards release dates and I really worried. 我正在接近发布日期,我真的很担心。

I assume that you use: 我假设您使用:

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

In this case you should not forget to call completion handler and according to Apple docs you have only 30 seconds to do so: 在这种情况下,你不应该忘记调用完成处理程序,根据Apple文档,你只有30秒这样做:

As soon as you finish processing the notification, you must call the block in the handler parameter or your app will be terminated. 处理完通知后,必须立即调用处理程序参数中的块,否则您的应用程序将被终止。 Your app has up to 30 seconds of wall-clock time to process the notification and call the specified completion handler block. 您的应用程序有最多30秒的挂钟时间来处理通知并调用指定的完成处理程序块。 In practice, you should call the handler block as soon as you are done processing the notification. 实际上,您应该在处理完通知后立即调用处理程序块。 The system tracks the elapsed time, power usage, and data costs for your app's background downloads. 系统会跟踪应用程序后台下载的已用时间,功耗和数据成本。 Apps that use significant amounts of power when processing remote notifications may not always be woken up early to process future notifications. 处理远程通知时使用大量电源的应用可能无法提前唤醒以处理将来的通知。

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

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