0

when my app is in foreground and receive push notification it displays notification on screen. After sometime (2-3 seconds) if user not tap the notification it goes, So my question is how can i handle push notification if user not tap on the notification. When the app is in foreground ios 10.0*

Just for example If user login at another device i will receive notification on previously logged in device, if app is in foreground the use will see the notification that login at another device, if user tap on notification it moves to the login screen, but what if user don't tap on notification

Jaydeep Vyas
  • 4,411
  • 1
  • 18
  • 44
  • In the example, you say that a different login is detected for the same user.. meaning that the user who is laready logged into device A will see a notification that a login was detected on device B... so why would he be redirected to login screen on device A after tapping the notification? – Prashant Jul 13 '17 at 12:31
  • yes i want exactly as u saying same user is redirect to login screen for other user to login means logged out automatically – Jaydeep Vyas Jul 13 '17 at 12:33
  • ok, got your query. But why would you want the user to be logged out? (if they didn't tap the notification). This link would help: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension/1845197-didreceivenotificationresponse – Prashant Jul 13 '17 at 12:39
  • @Prashant can you give me use of UNNotificationContentExtensionResponseOptionDismissAndForwardAction – Jaydeep Vyas Jul 13 '17 at 12:48
  • https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextensionresponseoption?language=objc I believe this would help you, you could fire the method to log a user out and display the login screen. – Prashant Jul 13 '17 at 12:59
  • i mean to say demo.. example – Jaydeep Vyas Jul 13 '17 at 13:00
  • I will try..till then go through the docs – Prashant Jul 13 '17 at 13:01
  • I guess there's an answer: https://stackoverflow.com/questions/39395513/how-to-handle-usernotifications-actions-in-ios-10 – Prashant Jul 13 '17 at 13:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149128/discussion-between-jaydeep-vyas-and-prashant). – Jaydeep Vyas Jul 13 '17 at 13:05

2 Answers2

1

You could add a ViewController in your app that saved the push notification's data. And when the user navigates there, they can view them.

Prashant
  • 336
  • 3
  • 18
0

The duration of push notification is a system defaulted property. The default behavior is for that to show up for 2-3 seconds, and dismissed automatically if it's not tapped. You cannot change the duration of a push notification itself.

Previously, there is a trick that you can have a longer customized sound for your notification which can hold it on screen for up to 30 seconds, but that's from 5 years ago. I doubt that this can still be used today in iOS 10.0

Fangming
  • 24,551
  • 6
  • 100
  • 90
  • @JaydeepVyas A push notification cannot stay on screen forever. Previously the maximum time out is set to be 30 secs. So it will always be dismissed in 30 seconds no matter what. – Fangming Jul 13 '17 at 12:27
  • If you want the user to see the notification, at any cost,I suggest you use interactive notifications. This link might help you: https://www.igeeksblog.com/how-to-use-interactive-notifications-in-ios-10/ – Prashant Jul 13 '17 at 12:27
  • @Prashant can you understand my question, i want user to logout if it not tapped on the notification after it disappear – Jaydeep Vyas Jul 13 '17 at 12:30
  • @JaydeepVyas So in your case, you are sending this push notification to tell user that his account is logged in from another device, right? So simply handle the push notification to logout user and bring him back to log in page. – Fangming Jul 13 '17 at 12:35
  • ok, got your query. But why would you want the user to be logged out? (if they didn't tap the notification). This link would help: https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension/1845197-didreceivenotificationresponse – Prashant Jul 13 '17 at 12:39