ios 解析来自 didReceiveRemoteNotification:fetchCompletionHandler 的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20009006/
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
Parse warning from didReceiveRemoteNotification:fetchCompletionHandler
提问by Arian Faurtosh
I am getting an error after adding this code from parse.com:
从 parse.com 添加此代码后,我收到错误消息:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState == UIApplicationStateInactive) {
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}
I don't really understand what is going on, but I am getting this warning in the log:
我真的不明白发生了什么,但我在日志中收到了这个警告:
You've implemented -[ application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
你已经实现了 -[ application:didReceiveRemoteNotification:fetchCompletionHandler:],但你仍然需要在你的 Info.plist 中你支持的 UIBackgroundModes 列表中添加“remote-notification”。
I think adding in your plist file UIBackgroundModes - remote-notification
would fix the problem,
我认为添加你的 plist 文件UIBackgroundModes - remote-notification
可以解决这个问题,
But when I do that, it changes the words to the follow:
但是当我这样做时,它会将文字更改为以下内容:
Required Background Modes
-> App downloads content in response to push notifications
Required Background Modes
-> App downloads content in response to push notifications
Which my app doesn't do, so I am confused as to why I am doing this in the first place.
我的应用程序没有这样做,所以我很困惑为什么我首先要这样做。
采纳答案by djshiow
If you don't intend to fetch data in response to a remote notification I think you can implement this delegate method:
如果您不打算获取数据以响应远程通知,我认为您可以实现此委托方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
e.g.
例如
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateInactive) {
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}
instead of the current one you're using.
而不是您正在使用的当前。
回答by Hemang
If you don't want to manually add key in your .plist
file then here's a graphical version of @MurraySagal's answer, follow the steps from 1 to 7 and you'll be done. :)
如果您不想在.plist
文件中手动添加密钥,那么这里是@MurraySagal 答案的图形版本,请按照步骤 1 到 7 操作即可完成。:)
Note: If you can't read out the steps, you can zoom out your current tab by using combination of Command++(for zoom in) and Command+-(for zoom out). If Commandwon't work, you can try with Ctrl.
注意:如果您无法读出步骤,您可以使用Command+ +(放大)和Command+ -(缩小)的组合来缩小当前选项卡。如果Command不起作用,您可以尝试使用Ctrl.
回答by jomafer
I think @djshiow is not solving your problem.
我认为@djshiow 没有解决您的问题。
You need to add the following in your info.plist file:
您需要在 info.plist 文件中添加以下内容:
1) Add a new row and, on the left column, select Required background modes.
1) 添加一个新行,然后在左列中选择Required background patterns。
2) On Item 0 row, click on the right column and type: remote-notification. Press Enter.
2) 在 Item 0 行上,单击右列并键入:remote-notification。按 Enter。
回答by Murray Sagal
In Xcode 6:
在 Xcode 6 中:
- In the Project Navigator click the project
- In the Projects and Targets list click the target.
- Click Capabilities
- Expand and turn on Background Modes
- Click Remote Notifications
- 在项目导航器中单击项目
- 在项目和目标列表中单击目标。
- 点击功能
- 展开并打开背景模式
- 单击远程通知
This will add the Required background modes
key and App downloads content in response to push notifications
value to info.plist
.
这会将Required background modes
键和App downloads content in response to push notifications
值添加到info.plist
.
回答by zevij
When you use the new didReceive... method you are expected to do two things:
当您使用新的 didReceive... 方法时,您需要做两件事:
- Add the necessary entry in your plist
- Add a completion handler that will handle the event for handling the data
- 在 plist 中添加必要的条目
- 添加一个完成处理程序来处理处理数据的事件
If you do not want to download any data, you can add this to your didReceive... method
如果您不想下载任何数据,可以将此添加到您的 didReceive... 方法中
completionHandler(.NoData)