简体   繁体   English

应用未运行或终止时发出通知

[英]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

  • For this you will need to have a Developer License to send remote notifications ( and the push certificate that comes with it ) 为此,您将需要具有开发者许可证才能发送远程通知(及其随附的推送证书)。
  • A backend with the tokens per device registered that is capable of contacting Apple APNs in case of a new notification 后端带有注册的每台设备的令牌,该令牌能够在出现新通知时与Apple APN联系

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.

相关问题 应用未运行/应用终止时如何获取推送通知 - How to get push notification when app is not running/app is terminated 当应用未运行(终止)时,通知应用有关远程推送通知的信息 - Notify the app about remote push notification when the app is not running (terminated) 应用未运行/应用终止时如何处理推送通知 - How to handle push notification when app is not running/app is terminated 当应用程序在后台/终止时如何忽略远程/推送通知 - How to ignore a remote/push notification while app is on background/terminated 应用终止时的远程通知 - Remote notification when app is terminated 应用程序终止时推送通知 - Push notification when app is terminated IOS如何在用户终止应用程序时从通知中心删除通知 - IOS how to remove notification from notification center while app is terminated by user 当应用程序处于后台或运行状态时,处理推送通知,而不是在应用程序终止时 - Handle push notification when app is in Background or Running state not when app is terminated 应用程序运行时的 Delphi Apple 推送通知 - Delphi Apple Push Notification while app is running iOS Swift - 推送通知:将所有远程通知保存在数据库中(也在应用程序终止时) - iOS Swift - push notification: Save all Remote-Notifications in a Database (also while App is terminated)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM