xcode 任何知道苹果应用程序是否收到推送通知的选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9731826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:40:21  来源:igfitidea点击:

any option to know if apple app get the push notification?

iphoneobjective-cxcodeapple-push-notifications

提问by user1273189

I build xcode app that get push notification, the main problem is that the push notification is very critical for me. so I want to check if the push notification is delivered to the device with the app installed, I understand that if the iphone dosn't have internet connecction / 3G the push notification is not getting to the device.

我构建了获取推送通知的 xcode 应用程序,主要问题是推送通知对我来说非常重要。所以我想检查推送通知是否已发送到安装了应用程序的设备,我知道如果 iphone 没有互联网连接/3G,推送通知不会到达设备。

how can I check if the device get the notification or not? how can I check if the APNS successful to deliver the push notification?

如何检查设备是否收到通知?如何检查 APNS 是否成功发送推送通知?

I want to send sms if the push notification is not deliver to the device so I think about the idea to get the notification event when it's open by the push notification, and to send request to my server so i can know if the push notification is successful deliver or not. the main problem is that the user need to open the app every time he get the notification and in the night it's a problem. so this option is not good for me.

如果推送通知没有发送到设备,我想发送短信,所以我考虑了在推送通知打开时获取通知事件的想法,并将请求发送到我的服务器,这样我就可以知道推送通知是否是成功交付与否。主要问题是用户每次收到通知时都需要打开应用程序,而在晚上这是一个问题。所以这个选项对我不利。

I check the feedback server push notification but i don't find any info that I can get if the push notification is delivered or not

我检查了反馈服务器推送通知,但我没有找到任何可以获取推送通知是否已发送的信息

any idea??

任何的想法??

回答by Lem

With iOS7 you have a new method called application:didReceiveRemoteNotification:fetchCompletionHandler: which you probably could use for your task. From Apple's Docs:

在 iOS7 中,您有一个名为 application:didReceiveRemoteNotification:fetchCompletionHandler: 的新方法,您可能可以将其用于您的任务。来自Apple 的文档

Implement this method if your app supports the remote-notification background mode. ... When a push notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method. Use this method to download any data related to the push notification. When your method is done, call the block in the handler parameter.

Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls this method regardless of the state of your app.

如果您的应用支持远程通知后台模式,请实现此方法。...当推送通知到达时,系统向用户显示通知并在后台启动应用程序(如果需要),以便它可以调用此方法。使用此方法下载与推送通知相关的任何数据。方法完成后,调用 handler 参数中的块。

与 application:didReceiveRemoteNotification: 方法不同,该方法仅在您的应用程序运行时调用,无论您的应用程序处于何种状态,系统都会调用此方法。

回答by Atulkumar V. Jain

There is no way to find out whether the notification was delivered to the device or no. APNS is a one way service. If there is no internet connection on the device then the APNS server will hold the last notification for some period of time which is no specified by Apple. If a new notification is sent to APNS for delivery then the old notification data is lost and replaced by the new data if its undelivered. If the notification is delivered then also the old notification data is deleted on the APNS server.

无法确定通知是否已发送到设备。APNS 是一种单向服务。如果设备上没有互联网连接,则 APNS 服务器将在 Apple 未指定的一段时间内保留最后一次通知。如果将新通知发送到 APNS 进行传递,则旧通知数据将丢失,如果未传递,则由新数据替换。如果传递了通知,则 APNS 服务器上的旧通知数据也会被删除。

Please go through the following link : Apple Push Notification

请通过以下链接:Apple Push Notification

Hope this helps you...........

希望这对你有帮助......

回答by Moshe

The short answer, you can't, since APNS is one way. However, since an app can execute arbitrary code upon receipt of a notification, you can use this to say, send an http request to your own server when the notification is recieved.

简短的回答,你不能,因为 APNS 是一种方式。但是,由于应用程序可以在收到通知后执行任意代码,因此您可以使用它来表示,在收到通知时向您自己的服务器发送 http 请求。

回答by jonkroll

There are any number of reason why push notifications might not get delivered to your user, or might not be delivered in a timely manner. Apple does not provide any mechanism for you to query the status of a push notification that you have sent.

推送通知可能无法发送给您的用户或可能无法及时发送的原因有很多。Apple 没有提供任何机制让您查询您发送的推送通知的状态。

If your app is currently running on the user's device and the user is accepting notifications for your app, you can implement the following method in your app delegate. It would be called whenever a push notification is received and in this method you could send a request back to your server to indicate the message was received. However this will only work while the user is running your app.

如果您的应用程序当前正在用户的设备上运行并且用户正在接受您应用程序的通知,您可以在您的应用程序委托中实现以下方法。每当收到推送通知时都会调用它,在这种方法中,您可以将请求发送回您的服务器以指示已收到消息。 但是,这仅在用户运行您的应用程序时有效。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

In general though, it sounds like you'e relying on push notifications for something you shouldn't. From Apple's Local and Push Notification Programming Guide:

但总的来说,听起来您似乎在依赖推送通知来获取您不应该做的事情。来自 Apple 的本地和推送通知编程指南

Important Because delivery is not guaranteed, you should not depend on the remote-notifications facility for delivering critical data to an application via the payload. And never include sensitive data in the payload. You should use it only to notify the user that new data is available.

重要 因为不能保证交付,所以您不应依赖远程通知工具通过有效负载将关键数据交付给应用程序。并且永远不要在有效负载中包含敏感数据。您应该仅使用它来通知用户有新数据可用。

回答by kalyanbk

If you are using JAVAPNS to send the APNS notification, you can use the below:

如果您使用 JAVAPNS 发送 APNS 通知,则可以使用以下命令:

List<PushedNotification> notifications = 
Push.combined("alert", badge, "default", "cert.p12", "certpassword", true, deviceToken);

for (PushedNotification notification : notifications) {
    if (notification.isSuccessful()) { 
       //Push is successful. Do your thing...
    }
    else {
       //Push is not successful. Do your thing...
    }
 }