gpt4 book ai didi

ios - Swift 3 '[UIApplicationLaunchOptionsKey : Any]?' 不可转换为 '[String : NSString]'

转载 作者:可可西里 更新时间:2023-11-01 01:25:53 26 4
gpt4 key购买 nike

我有一个 TVOS 应用程序,它已从 Swift 2 转换为 Swift 3,但出现以下错误。我不确定如何让它静音。

'[UIApplicationLaunchOptionsKey:任何]?不能转换为“[String : NSString]”

它出现在这段代码中

appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL

if let launchOptions = launchOptions as? [String: AnyObject] {
for (kind, value) in launchOptions {
appControllerContext.launchOptions[kind] = value
}
}

enter image description here

添加:

/*
Copyright (C) 2015 Hani Hamrouni. All Rights Reserved.


*/

import UIKit
import TVMLKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate {
// MARK: Properties

var window: UIWindow?

var appController: TVApplicationController?

//change the link to your host url

static let TVBaseURL = "http://google.com"

static let TVBootURL = "\(AppDelegate.TVBaseURL)js/application.js"

// MARK: UIApplication Overrides

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)

/*
Create the TVApplicationControllerContext for this application
and set the properties that will be passed to the `App.onLaunch` function
in JavaScript.
*/
let appControllerContext = TVApplicationControllerContext()

/*
The JavaScript URL is used to create the JavaScript context for your
TVMLKit application. Although it is possible to separate your JavaScript
into separate files, to help reduce the launch time of your application
we recommend creating minified and compressed version of this resource.
This will allow for the resource to be retrieved and UI presented to
the user quickly.
*/
if let javaScriptURL = URL(string: AppDelegate.TVBootURL) {
appControllerContext.javaScriptApplicationURL = javaScriptURL
}

appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL

if let launchOptions = launchOptions {
for (kind, value) in launchOptions {
appControllerContext.launchOptions[kind.rawValue] = value as AnyObject
}
}


appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)

return true
}

// MARK: TVApplicationControllerDelegate

func appController(_ appController: TVApplicationController, didFinishLaunching options: [String: Any]?) {
print("\(#function) invoked with options: \(options)")
}

func appController(_ appController: TVApplicationController, didFail error: Error) {
print("\(#function) invoked with error: \(error)")

let title = "Error Launching Application"
//error message
let message = error.localizedDescription
let alertController = UIAlertController(title: title, message: message, preferredStyle:.alert )

self.appController?.navigationController.present(alertController, animated: true, completion: { () -> Void in
// ...
})
}

func appController(_ appController: TVApplicationController, didStop options: [String: Any]?) {
print("\(#function) invoked with options: \(options)")
}
}

最佳答案

你最好按原样使用 [UIApplicationLaunchOptionsKey : Any]

这是怎么回事?

    if let launchOptions = launchOptions {
for (kind, value) in launchOptions {
appControllerContext.launchOptions[kind.rawValue] = value
}
}

已更新

似乎 TVApplicationControllerContext 的属性 launchOptions 的类型是 [String: Any],所以你不需要用 作为 AnyObject

关于ios - Swift 3 '[UIApplicationLaunchOptionsKey : Any]?' 不可转换为 '[String : NSString]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41506804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com