PeakGen
PeakGen

Reputation: 23035

AppDelegate.swift: overriding declaration requires an 'override' keyword

I am trying to add the following code line into my Flutter application's AppDelegate.swift file because I am using Amazon S3, you can read about this config here - https://pub.dev/packages/amazon_s3_cognito#ios

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    // Store the completion handler.
    AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

Below is my code

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    // Store the completion handler.
    AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}
}

However this is throwing me the following error.

Launching lib/main.dart on iPhone 13 in debug mode...
Xcode build done.                                           10.4s
Failed to build iOS app
Error output from Xcode build:
↳
    objc[28776]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x20d9bab90) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x105f9c2c8). One of the two will be used. Which one is undefined.
    objc[28776]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x20d9babe0) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x105f9c318). One of the two will be used. Which one is undefined.
    --- xcodebuild: WARNING: Using the first of multiple matching destinations:
    { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
    { platform:iOS Simulator, id:1ABD0743-E247-4003-A707-FF32B0D919CC, OS:15.2, name:iPad (9th generation) }
    { platform:iOS Simulator, id:0C55A691-D2B7-41C0-931C-3FA45254EBEE, OS:15.2, name:iPad Air (4th generation) }
    { platform:iOS Simulator, id:D6A98800-F0AC-479B-8296-AED806661D77, OS:15.2, name:iPad Pro (9.7-inch) }
    { platform:iOS Simulator, id:AEB0F448-88CF-46BA-B7F2-86F73FC2D06A, OS:15.2, name:iPad Pro (11-inch) (3rd generation) }
    { platform:iOS Simulator, id:640C9AB6-6852-4F25-A598-414D44F36708, OS:15.2, name:iPad Pro (12.9-inch) (5th generation) }
    { platform:iOS Simulator, id:C45E1FFD-A4B1-4E69-9D41-EF52944DCFF6, OS:15.2, name:iPad mini (6th generation) }
    { platform:iOS Simulator, id:C3118792-4E05-4971-9E70-97E8BEF2AF8E, OS:15.2, name:iPhone 8 }
    { platform:iOS Simulator, id:C87519E9-C754-49BE-A0BE-BCEA9D823C8F, OS:15.2, name:iPhone 8 Plus }
    { platform:iOS Simulator, id:5E7237C4-7239-446D-AA20-97625673CCA5, OS:15.2, name:iPhone 11 }
    { platform:iOS Simulator, id:4F0B2537-04B5-4ED8-90F0-076C819A5783, OS:15.2, name:iPhone 11 Pro }
    { platform:iOS Simulator, id:272A8C28-47BC-46B9-8B2F-6DD5B3B561CE, OS:15.2, name:iPhone 11 Pro Max }
    { platform:iOS Simulator, id:F965B511-D3F6-428D-BC40-4B3C620B5720, OS:15.2, name:iPhone 12 }
    { platform:iOS Simulator, id:114A3386-66D5-4C36-BDB5-574FE1C07067, OS:15.2, name:iPhone 12 Pro }
    { platform:iOS Simulator, id:155E2EF9-E9AD-4F74-A7F9-A9702A708080, OS:15.2, name:iPhone 12 Pro Max }
    { platform:iOS Simulator, id:D7D7C57E-25D2-4A6F-8956-442EB0DD524F, OS:15.2, name:iPhone 12 mini }
    { platform:iOS Simulator, id:3C432DFA-3D27-472F-AF97-A71AC22DC5DA, OS:15.2, name:iPhone 13 }
    { platform:iOS Simulator, id:58F3389A-38B0-42F0-8A0A-8D7279D14D55, OS:15.2, name:iPhone 13 Pro }
    { platform:iOS Simulator, id:9C77C570-7653-40BE-B18D-1E9ECF0A0162, OS:15.2, name:iPhone 13 Pro Max }
    { platform:iOS Simulator, id:FAF7A709-FC97-4445-A8ED-478ED5972DF6, OS:15.2, name:iPhone 13 mini }
    { platform:iOS Simulator, id:7D146971-E6B4-4CA0-AB3A-4F41DDB5E59F, OS:15.2, name:iPhone SE (2nd generation) }
    { platform:iOS Simulator, id:F293BCDE-386F-4AF8-B3CE-91F0E96C253B, OS:15.2, name:iPod touch (7th generation) }
    { platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-001978AE1ADA001E }
    { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
    ** BUILD FAILED **
Xcode's output:
↳
    /Users/xxxwxxx/Documents/projects/flutter/xxx/xxx-customer/ios/Runner/AppDelegate.swift:13:8: error: overriding declaration requires an 'override' keyword
      func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
           ^
      override
    Flutter.FlutterAppDelegate:71:15: note: overridden declaration is here
        open func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void)
                  ^
    /Users/xxxwxxx/Documents/projects/flutter/xxx/xxx-customer/ios/Runner/AppDelegate.swift:15:5: error: cannot find 'AWSS3TransferUtility' in scope
        AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
        ^~~~~~~~~~~~~~~~~~~~
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in dependency order
    /Users/xxxwxxx/Documents/projects/flutter/xxx/xxx-customer/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'FMDB' from project 'Pods')
    /Users/xxxwxxx/Documents/projects/flutter/xxx/xxx-customer/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'BSImageView' from project 'Pods')
    /Users/xxxwxxx/Documents/projects/flutter/xxx/xxx-customer/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'BSGridCollectionViewLayout' from project 'Pods')
Could not build the application for the simulator.
Error launching application on iPhone 13.
Exited (sigterm)

I must admit that I lack the native iOS development knowledge. What is going wrong here?

Upvotes: 0

Views: 1282

Answers (1)

Chiziaruhoma Ogbonda
Chiziaruhoma Ogbonda

Reputation: 411

You have two application methods, the second one should be overridden as follows

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  override func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    // Store the completion handler.
    AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
  }
}

Upvotes: 2

Related Questions