-1

I am trying to setup Notifcations on Xcode 11 in iOS13 but i tried adding the linked frameworks(in pic) but still doesn't recognize the module. Any suggestions?

import UIKit
import Firebase
import UNUserNotificationCenter


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        let center = UNUserNotificationCenter.current()
        // Request permission to display alerts and play sounds.
        center.requestAuthorization(options: [.alert, .sound])
           { (granted, error) in
              // Enable or disable features based on authorization.
           }
        return true
    }

enter image description here

Di Nerd Apps
  • 770
  • 8
  • 15

3 Answers3

0

Change

import UNUserNotificationCenter

to

import UserNotifications
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Also you should not need to do any manual linking with frameworks as you are doing; delete all those. `import` with a module name links you automatically. – matt Oct 01 '19 at 03:48
  • i tried UserNotifications and it didnt recognize it either , the only one it offered tho from autocomplete was UNUserNoticaitionCenter but still says it doesnt recognize it – Di Nerd Apps Oct 01 '19 at 04:00
  • I assure you that `import UserNotifications` works. – matt Oct 01 '19 at 04:04
  • ok but how can i get it to show up or recognize it as a module, because it keeps saying module not found ? – Di Nerd Apps Oct 01 '19 at 04:08
0

For me to fix this i had to remove the import UNUserNotifications and just write the code below . Not sure why but import UserNotfications was not working for me . Remove linked frameworks if added.

Also I found the fix on Apples website here https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications

import UIKit
import Firebase


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        let center = UNUserNotificationCenter.current()
        // Request permission to display alerts and play sounds.
        center.requestAuthorization(options: [.alert, .sound])
           { (granted, error) in
              // Enable or disable features based on authorization.
           }
        return true
    }
Di Nerd Apps
  • 770
  • 8
  • 15
  • 1
    That’s impossible. If you say “UNUserNotificationCenter” in your code, it won’t compile unless you import UserNotifications. Plus how is this code different from what you had before? – matt Oct 01 '19 at 05:28
  • Idk why it worked but it’s the only way I could build and have it run successfully. I removed the import for UNUserNotificationCenter and just called it as shown in code. It is even mentioned on apples website I posted link – Di Nerd Apps Oct 01 '19 at 11:28
  • Apple website about UNUserNotificationCenter : https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications – Di Nerd Apps Oct 01 '19 at 17:34
0

Just retried this and now Xcode is working fine with just UserNotfications and doesnt now recognize UNUserNotificationCenter

Di Nerd Apps
  • 770
  • 8
  • 15