简体   繁体   中英

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.

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 .

  • 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 has also since released PushKit, as far as I can tell it requires at least iOS8+ if you're app is terminated, however.

For more information see here: VoiP Push notifications best practices

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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