ios - 关闭应用程序时如何从推送通知中获取数据?
<p><p>我想在应用关闭时从推送通知中获取数据。我正在使用下面给出的以下代码:</p>
<pre><code>- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSDictionary *aps = userInfo[@”aps”];
if (state == UIApplicationStateInactive){
// user tapped notification
NSLog(@"results%@",aps);
completionHandler(UIBackgroundFetchResultNewData);
} else {
// app is active
completionHandler(UIBackgroundFetchResultNoData);
}
}
</code></pre>
<p>在上面的代码中 NSLog(@"results%@",aps);应用程序在后台时不会打印值。请帮帮我</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>didReceiveRemoteNotification 仅在您点击通知时有效。所以它只会在您点击通知时为您提供数据,并且您的应用会打开。</p>
<p>如果要获取 NSDictionary *aps = userInfo[@”aps”];当您的应用程序处于终止状态时,您必须实现 pushkit 框架。</p>
<p>您可以从 1 my answer 下载示例代码</p>
<p> <a href="https://stackoverflow.com/questions/38235676/can-someone-share-a-sample-code-of-ios-xamarin-pushkit-in-c/38303750#38303750" rel="noreferrer noopener nofollow">Can someone share a sample code of iOS Xamarin PushKit in C#?</a> </p>
<p> <a href="https://stackoverflow.com/questions/37868158/register-for-voip-notifications-outside-of-app-delegate/38147175#38147175" rel="noreferrer noopener nofollow">Register for voip notifications outside of app delegate</a> </p>
<p><strong>来源</strong> <a href="https://github.com/hasyapanchasara/PushKit_SilentPushNotification" rel="noreferrer noopener nofollow">https://github.com/hasyapanchasara/PushKit_SilentPushNotification</a> </p></p>
<p style="font-size: 20px;">关于ios - 关闭应用程序时如何从推送通知中获取数据?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38429156/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38429156/
</a>
</p>
页:
[1]