该问题通常是由于在不同的方法中重复定义了相同名称的回调函数所导致。解决方法是去除冲突的函数定义或更改函数名称以避免冲突。
下面是一个重写错误的示例:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// some code here
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
// some code here
}
在上面的示例中,第二个方法 didReceiveRemoteNotification
与 AppDelegate
中的默认回调函数相同,导致编译错误。可以将其重命名以避免冲突,如下所示:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// some code here
}
func newMethodForRemoteNotifications(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
// some code here
}