简体   繁体   English

如何仅在应用程序中使用iOS推送通知

[英]How to consume iOS Push notification in the app only

I am working on a app, where I need to send a push notification to the app to start processing data as needed. 我正在开发一个应用程序,在该应用程序中,我需要向该应用程序发送推送通知以开始根据需要处理数据。

How do I send a push notification to the device so that instead of showing the alert message , the notification is forwarded to the app - whether the app is in the foreground or background.. 如何push notificationpush notification发送到设备,以便不显示alert message ,而是将notification转发到应用程序-无论应用程序是前台还是后台。

I did implement the delegate method : 我确实实现了委托方法:

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

however this is called only when the app is in the foreground . 但是,只有在应用程序处于foreground时才调用此方法。 When the app is in the background the notification shows up on the notification center . 当应用程序在backgroundnotification显示在notification center

Please advice. 请指教。

To make this works you need to do few step: 要使其工作,您需要执行以下步骤:

  • set background mode remote-notification 设置后台模式远程通知

  • implement application:didReceiveRemoteNotification:fetchCompletionHandler: method in app delegate 在应用程序委托中实现application:didReceiveRemoteNotification:fetchCompletionHandler:方法

  • and make sure push notification payload contains key "content-available" : 1 并确保推送通知有效"content-available" : 1包含键"content-available" : 1

related docs: 相关文档:

App States and Multitasking 应用状态和多任务

Local and Push Notifications in Depth 深度本地通知和推送通知

Is your application using a backend? 您的应用程序使用后端吗? An example would be Parse or another to store your data. 一个例子是解析或另一个来存储您的数据。

Parse, for example, allows you to add push notifications that can be customized and changed to get the most out of your application. 例如,使用Parse,您可以添加可以自定义和更改的推送通知,以充分利用您的应用程序。

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

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