简体   繁体   English

在应用中推送通知

[英]Push notification while in App

I have successfully set up a MySQL+PHP push notification server and everything is working fine and dandy, except for one thing. 我已经成功设置了一个MySQL + PHP推送通知服务器,除了一件事之外,其他所有东西都工作正常。 If the user happens to be in the app, they do not get the push notification, which is kind of annoying. 如果用户恰巧在应用程序中,则他们不会收到推送通知,这很烦人。 Is there a way I can modify this so it will show the push notification in Notification Center or something? 有什么办法可以修改它,以便它在通知中心或其他内容中显示推送通知?

Thanks for the help in advance! 我在这里先向您的帮助表示感谢!

When app is running below method is called 当应用程序在下面运行时,将调用方法

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

You cannot add anything to notification center using SDK. 您无法使用SDK向通知中心添加任何内容。 If notification is received when app is not running iOS add it in the notification center. 如果在应用未运行iOS时收到通知,则将其添加到通知中心。 You can show alert yourself in above method like this 您可以通过上述方法向自己显示警报

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
   //show alert
}

If your user is in the app your app will get a message to the app delegate. 如果您的用户在应用程序中,则您的应用程序将收到一条消息给应用程序委托。 See 看到

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

in the Apple Documentation Apple文档中

You cant put a notification in notification center while the app is open. 打开应用程序后,您无法在通知中心中放置通知。 Notification center is designed to capture notifications that happen while the app is not active. 通知中心旨在捕获在应用程序不活动时发生的通知。 However the call to the app delegate is useful as you can display the notification to the user in any way you want to, including building your own notification center style animation if thats what you want. 但是,调用应用程序委托很有用,因为您可以以任何想要的方式向用户显示通知,包括根据需要构建自己的通知中心样式动画。

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

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