Create user notification issues using Swift UI

“Cannot convert return expression of type 'Void' to return type 'Bool'” How to solve it?
Answered by OOPer in 668338022
As you can see, the method application(_:didFinishLaunchingWithOptions:) is declared with ->Bool, which means you need to return a Bool value from the method. In case of application(_:didFinishLaunchingWithOptions:), it should be true usually.
Code Block
func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]){(granted,error)in
if granted {
print("User notifications are allowed.")
} else {
print("User notifications are not allowed.")
}
}
return true //<-
} //End `application(_:didFinishLaunchingWithOptions:)`



One more, please use the Code block feature (icon <> below the editing area) when you show some code as text.
help
import UIKit

import CoreData



@UIApplicationMain

class AppDelegate: UIResponder,UIApplicationDelegate{

    func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{

        
//Cannot convert return expression of type 'Void' to return type 'Bool'
       
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]){(granted,error)in

            if granted{

                print("User notifications are allowed.")

                

            }else{

                print("User notifications are not allowed.")

            }

            

        }

        

    }

}
Accepted Answer
As you can see, the method application(_:didFinishLaunchingWithOptions:) is declared with ->Bool, which means you need to return a Bool value from the method. In case of application(_:didFinishLaunchingWithOptions:), it should be true usually.
Code Block
func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]){(granted,error)in
if granted {
print("User notifications are allowed.")
} else {
print("User notifications are not allowed.")
}
}
return true //<-
} //End `application(_:didFinishLaunchingWithOptions:)`



One more, please use the Code block feature (icon <> below the editing area) when you show some code as text.
Thank you very much
Create user notification issues using Swift UI
 
 
Q