[英]notification while app is not running or terminated
i am working on app in which i am using local notification when any other user post data in app.It works fine when my app is running and shows notification also. 我正在处理其中任何其他用户在应用程序中发布数据时使用本地通知的应用程序,当我的应用程序运行时也可以正常工作并显示通知。 but when i terminate my app and any other user post data i can't get notification.
但是当我终止我的应用程序和任何其他用户的帖子数据时,我无法收到通知。 Is there any way to call function of notification while my app is terminated??
我的应用终止时,有什么方法可以调用通知功能?
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
notification.alertBody = [NSString stringWithFormat:@"one person vote your post"];
[notificationArray addObject:@"one person vote your post"];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
If you get others post from server(get using web service), you should implement push notification instead local notification. 如果您从服务器获取其他帖子(使用Web服务),则应实施推送通知,而不是本地通知。
Local Notification : you need to specified fire time when your app is in use. 本地通知:您需要在使用应用时指定启动时间。
in your case your app is not running when other user post. 如果您的应用在其他用户发布时未运行。 so you are not get trigger event.
这样就不会触发事件。
I think what you're looking for is using remote notifications but still executing local code and then in return reposting a local notification to notify the user. 我认为您正在寻找的是使用远程通知,但仍在执行本地代码,然后作为回报重新发布本地通知以通知用户。
Apple has realised the need for this and added Silent Remote Notifications
. 苹果已经意识到了这一点的必要性,并增加了
Silent Remote Notifications
。
Apple has also since released PushKit, as far as I can tell it requires at least iOS8+ if you're app is terminated, however. 苹果还发布了PushKit,据我所知,如果您的应用被终止,它至少需要iOS8 +。
For more information see here: VoiP Push notifications best practices 有关更多信息,请参见此处: VoiP推送通知最佳做法
I have recently asked a question about it on Security.stackexchange.com with a very comprehensive answer posted by the community: WhatsApp and end-to-end encryption , which I highly encourage you reading through as I think it is in a similar area where WhatsApp seems to already having achieved it. 我最近在Security.stackexchange.com上问了一个有关该问题的问题,社区提供了一个非常全面的答案: WhatsApp和端到端加密 ,我强烈建议您仔细阅读,因为我认为它位于相似的领域, WhatsApp似乎已经实现了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.