Foreground notifications (ch. 8) don't work (ver 0.2)

I’ve tried following chapter 8 and everything was going smoothly until I reached Foreground notifications section (p. 90 in ver. 0.2) – basically, I can’t get them to work. I’m using Xcode 8 beta 6 and neither on my iPhone 5 with iOS 10 beta 7 as well as iPhone SE simulator notifications don’t show up when and app is still in foreground.

What is interesting is that I get a warning in the UNUserNotificationCenterDelegate method saying:

Instance method userNotificationCenter(_:willPresent:withCompletionHandler:) nearly matches optional requirement userNotificationCenter(_:willPresent:withCompletionHandler:) of protocol UNUserNotificationCenterDelegate

Fix-It suggests either making it private (tried that, doesn’t make any difference) or adding @nonobjc.

My AppDelegate.swift looks like this:

import UIKit
import UserNotifications

let userNotificationReceivedNotificationName = Notification.Name("com.raywenderlich.CuddlePix.userNotificationReceived")
let newCuddlePixCategoryName = "newCuddlePix"

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?

  private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UNUserNotificationCenter.current().delegate = self
    return true
  }
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
        completionHandler(.alert)
    }
}

Am I doing something wrong or is there a bug that I am not aware of?

Thanks!

I am seeing the same issue. Any fixes?

Also having same issues. Just tried it on the phone with iOS 10 Beta 8, still not working

Also the extension notification doesnt look like the book. Even running the final project the notification is huge.

Does anyone else see this?

iOS10 beta 8
Xcode 8

Yep, same problem with a huge image in the notification extension as well. I’m also on the latest betas.

By the way, I think I found a cause of the warning that I’ve mentioned in my first post: ios - application(_:didFinishLaunchingWithOptions:)' nearly matches optional requirement - Stack Overflow

Based upon the info from adrianziobro above I have been able to “fix” this. The method signature for the notification delegate method is no longer valid in the current version of Xcode. Change the method signature to the one below and the method fires as desired. Thanks adrianziobor for steering me in the correct direction. The new signature is the one documented in the preliminary docs.

Here’s the working(as of Xcode beta 6 and iOS 10 beta 8) method header:

func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) → Void)

Perhaps Ray or someone will take a look at this and post a fix. Thanks.

Did the fix I posted not work for you. It is continuing to work well for me

It did. But so did the following ??

internal func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping(UNNotificationPresentationOptions) -> Void) {
    ...
}

Thanks for the help.

Actually, it is not the use of “internal” that makes it work, but the @escaping that is required which is what you were saying. Thanks!
Another issue:
When I add the ContentExtension sample code and run the finished example, dragging the banner results in a very large cactus image filling the full window. Any thoughts? Have you done this part of the tutorial?
I’ve worked through the code twice – same result.