2

I am writing an application that utilizes Apple's Push Notification Service. Some of the push notifications are based on the users location and should only be delivered if the user is a certain distance from an object. I don't want to continually update the user's position to my server and do the check that way, first, because of security reasons and second, to cut down on the network usage. Is there a way, when the push notification is received by the device, to do a check before the user is notified, and if it doesn't meet the criteria, discard the notification? Thanks for the help!

4

3 回答 3

3

不,遗憾的是,如果用户在应用程序未启动时单击通知,您将无法在客户端执行任何代码。您必须在服务器端进行检查以决定是否发送推送。

于 2013-02-25T23:36:53.910 回答
1

当您的应用程序未运行(最典型的情况)时收到的推送通知不在您的控制范围内。一旦发送,它们将被接收并显示给用户(假设用户已授予权限)

如果在您的应用程序运行时收到推送通知,您确实可以控制它们。

也许您可以改用本地通知(从用户设备生成和接收的通知)。您可以完全控制它们何时生成。

请记住,应用程序中的后台处理是不允许的,除了 4 件事

  1. 位置跟踪(您可以在用户更改地理位置时订阅触发代码)
  2. 警报
  3. 玩音乐
  4. IP语音

这些之外的任何东西都不能在后台执行。

于 2013-02-25T23:45:58.747 回答
0

从 iOS7 开始,您的代码可以运行,我引用,“与用户看到通知的时间大致相同”:

多任务增强

使用推送通知通知用户有新内容可用的应用程序可以在后台获取内容。要支持此模式,请在应用的 Info.plist 文件中包含带有远程通知值的 UIBackgroundModes 键。您还必须在您的应用委托中实现 application:didReceiveRemoteNotification:fetchCompletionHandler: 方法。

在此处查看更多信息:

https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW10

和这里:

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW57

我还没有尝试过,但我想知道你是否发送了一个推送通知有效负载,它在“apns”中没有标准的“alert”、“badge”值但在自定义值中,它仍然会调用你的代码但没有显示推送通知。

于 2015-04-24T20:50:31.247 回答