I want to display Push Notifications in Foreground State for iOS 8.0
. I'm receiving notifications in background state, but not in foreground state.
Asked
Active
Viewed 1,346 times
2
-
2Possible duplicate of [Registering for Push Notifications in Xcode 8/Swift 3.0?](https://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0) – Hexfire Sep 20 '17 at 05:46
-
@Hexfire I want to display Push Notifications in Foreground State for iOS 8.0,i m receiving notifications in background state – anuj Sep 27 '17 at 12:38
-
Possible duplicate of [Get push notification while App in foreground iOS](https://stackoverflow.com/questions/14872088/get-push-notification-while-app-in-foreground-ios) – mfaani Oct 02 '17 at 20:51
-
@Hexfire That's for +iOS10. This question is for iOS8. So you got the wrong question. It's duplicate of *another* question – mfaani Oct 02 '17 at 20:56
-
have you got any solutions? I'm facing this problem too – Minnie Oct 18 '17 at 19:22
-
@Frank still searching for solutions – anuj Oct 23 '17 at 07:11
1 Answers
1
extension AppDelegate: UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(UNNotificationPresentationOptions.alert)
//completionHandler([.alert,.badge])
let userInfo = notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
}
// Print full message.
print(userInfo)
completionHandler([])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response:UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler()
}
}

Renan Kosicki
- 2,890
- 2
- 29
- 32

Ctan Li
- 177
- 3
- 13
-
completionHandler(UNNotificationPresentationOptions.alert) is what you need. – Ctan Li Oct 02 '17 at 20:48
-
that's for iOS10. The question is about iOS 8. See [here](https://stackoverflow.com/questions/14872088/get-push-notification-while-app-in-foreground-ios) – mfaani Oct 02 '17 at 20:56
-
-
@CtanLi als because i already getting notifications in iOS 10 in foreground i want in iOS 8 – anuj Oct 03 '17 at 11:27