It seems to be a problem peculiar to iOS14, but if the ProductName of the app contains a specific character (probably other than the alphabet), it will be used when implementing Push notification. ʻUNUserNotificationCenter.current (). requestAuthorization (options :, completionHandler :) `The method is flipped with an error and the pop-up asking the user for permission to notify disappears.
In my case, I put hiragana in ProductName (why I put it in ...), and I was addicted to it because the pop-up did not appear, so I will describe the details of the error and the solution.
You can find all the details of this issue in the Apple Developer Forums. If you are fluent in English, I think it is faster to read the link. https://developer.apple.com/forums/thread/660715
AppDelegate
import UIKit
import UserNotifications
***
class AppDelegate: UIResponder, UIApplicationDelegate {
***
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { granted, error in
print(error)
guard error == nil else { return }
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
})
return true
}
}
When sending push notifications to users, use the requestAuthrization ()
method of ʻUNUserNotificationCenter to ask for permission, but if there is a problem with ProductName, it will be played with an error in
completionHandlerand
registerForRemoteNotifications ()` will be executed. The pop-up display is not executed.
If you check the contents with print (error)
, it will be displayed on the console as follows.
Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application"
Change the ProductName in the TARGETS-> BuildSettings-> Packaging item to something that works (officially says simple ASCII characters). The Product Name is invisible to the user, so you don't have to think too much about it.
If you want to use hiragana or kanji in a place that the user can see (such as the app name under the app icon), add an item called Bundle Display Name to Info.plist and enter the app name you want to display there. To do.
The pop-up was displayed without any problem.
that's all.