ios - 在应用程序未运行时处理推送通知(即完全被杀死)
<p><p>我可以向我的 IOS 设备发送推送通知。但是,当我单击该通知时,它只会打开应用程序。应用程序内不显示任何消息。 </p>
<p>我使用的代码:</p>
<pre><code>if (application.applicationState == UIApplicationStateActive) {
NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
NSString *message = [ valueForKey:@"alert"];
UIAlertView *alertView = [ initWithTitle:@"Some title"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
;
;
} else {
//Do stuff that you would do if the application was not active
}
</code></pre>
<p>但无法在上述代码的帮助下显示我的消息。上面的代码仅在我的应用程序处于前台状态打开时才有效,而不是仅显示此警报。</p>
<p>请帮忙。</p>
<p>谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>当应用程序被完全杀死时获取通知代码</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
//opened from a push notification when the app is closed
NSDictionary* userInfo = ;
if (userInfo != nil)
{
NSLog(@"userInfo->%@",);
//write you push handle code here
}
}
}
</code></pre>
<p>更多信息请点击此链接:<a href="https://stackoverflow.com/questions/35058870/handling-push-notifications-when-app-is-terminated" rel="noreferrer noopener nofollow">Handling Push Notifications when App is Terminated</a> </p></p>
<p style="font-size: 20px;">关于ios - 在应用程序未运行时处理推送通知(即完全被杀死),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38512456/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38512456/
</a>
</p>
页:
[1]