Как я могу получить значение json массива из Firebase remote-config? (Swift) - PullRequest
1 голос
/ 18 октября 2019

Я использую Firebase Remote Config для сравнения версии приложения с обновлением, но не могу получить значение Remote Config.

Как я могу получить значение, например, массив json с swift?

ВотМое значение

[
{
"version": "1.0.4",
"status": "2",
"text": "Fix Error"
}
]

А вот и мой код

Получить значение:

class ConstraintValues {
static let shared = ConstraintValues()
init() {
    RemoteConfig.remoteConfig().setDefaults(["a":"b" as NSObject])
    let debugSettings = RemoteConfigSettings()
    RemoteConfig.remoteConfig().configSettings = debugSettings
}
func fetch(completetion:@escaping ( _ stringarray:String?)->()) {
    RemoteConfig.remoteConfig().fetch(withExpirationDuration: 0) { (status, error) in
        if let error = error {
            print(error)
            completetion(nil)
            return
        }
        RemoteConfig.remoteConfig().activate()
        let rc = RemoteConfig.remoteConfig().configValue(forKey: "VERSION")

        do {
            let json = try JSONSerialization.jsonObject(with: rc.dataValue, options: .allowFragments) as! [String:String]

            guard let dictionary1 = json["version"] else {return }
            guard let dictionary2 = json["text"] else {return }
            guard let dictionary3 = json["status"] else {return }
            completetion(dictionary1)
            completetion(dictionary2)
            completetion(dictionary3)
        }
        catch let error{
            print(error)
            completetion(nil)
        }

    }
}}

Проверить версию:

func checkversion(controller:UIViewController){
    ConstraintValues.shared.fetch { (version) in
        let cversion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! NSString//localversion
         let url = URL(string: "https://www.google.com/")
        let appStore = version//newversion
        //Compare
        let versionCompare = cversion.compare(appStore! as String, options: .numeric)
        if versionCompare == .orderedSame {
            print("same version")
        } else if versionCompare == .orderedAscending {

            let alertc = UIAlertController(title: "UPDATE!!", message: "New Version: \(version!)", preferredStyle: .alert)
            let alertaction = UIAlertAction(title: "Update", style: .default, handler: { (ok) in
                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(url!, options: [:], completionHandler: nil)
                } else {
                    UIApplication.shared.openURL(url!)
                }
            })
            alertc.addAction(alertaction)
            controller.present(alertc, animated: true, completion: nil)

        } else if versionCompare == .orderedDescending {

        }
    }
}

Я могу взять "версия ":" 1.0.4 ", но" текст "не может быть получен. Как мне поступить для этого метода?

...