iOS 14では、SwiftUIアプリはAppプロトコルに従い、UIApplicationDelegateには従いませんが、いくつかのシナリオでは、プッシュ登録、メモリ警告の処理など、古いAppdelegateからライフサイクル関数を使用する必要があります。
1.まず、UIApplicationDelegateに従うクラスを作成します。
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
//add code when didFinishLaunchingWithOptions
return true
}
}
@main
struct NewIn14App: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
モバイルの新機能を毎日学び、技術的な問題を議論します。クーポンで参加無料。