iOS 13
Chỉ khi mục tiêu là 13 hoặc lớn hơn.
SceneDelegate
không được hỗ trợ trước iOS 13 . Nếu bạn muốn sử dụng SceneDelegate
và cũng muốn hỗ trợ iOS trước iOS 13 thì bạn phải thêm một số thay đổi cho dự án của mình.
- Thêm thuộc tính sẵn có cho cả lớp trong tệp SceneDelegate.swift .
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
}
- Tệp AppDelegate.swift có hai
SceneDelegate
phương thức mới . Thêm thuộc tính sẵn có cho họ là tốt.
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
...
}
@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
...
}
- Cuối cùng, thêm
UIWindow
đối tượng trong AppDelegate.swift .
class AppDelegate: UIResponder, UIApplicationDelegate {
//Add this line
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
...
}
iOS 12 trở về trước
AppDelegate
cần một UIWindow
tài sản. iOS 13 sử dụng SceneDelegate
trong các dự án mới. Chỉ định UIWindow
đối tượng và xóa tệp SceneDelegate.swift .
Nếu bạn đã xóa SceneDelegate
dự án khỏi dự án, thì bạn phải xóa từ điển Bản khai cảnh ứng dụng khỏi Info.plist .
