ios - 是否可以向 iOS 应用程序用户发送更新通知

标签 ios swift objective-c app-store

我有一个应用程序已经在应用程序商店中上线。是否可以在有新更新时向所有用户发送更新通知?

最佳答案

应用版本比较的代码是:

 func checkAppUpdateAvailability(onSuccess: @escaping (Bool) -> Void, onError: @escaping (Bool) -> Void) {
        guard let info = Bundle.main.infoDictionary,
              let curentVersion = info["CFBundleShortVersionString"] as? String,
              let url = URL(string: "http://itunes.apple.com/lookup?bundleId=com.facebook.app") else {
            return onError(true)
        }
        do {
            let data = try Data(contentsOf: url)
            guard let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any] else {
               return onError(true)
            }
            if let result = (json["results"] as? [Any])?.first as? [String: Any], let appStoreVersion = result["version"] as? String {
                print("version in app store", appStoreVersion," current Version ",curentVersion);
                let versionCompare = curentVersion.compare(appStoreVersion, options: .numeric)
                if versionCompare == .orderedSame {
                    onSuccess(false)
                } else if versionCompare == .orderedAscending {
                    onSuccess(true)
                    // 2.0.0 to 3.0.0 is ascending order, so ask user to update
                }
            }
        } catch {
            onError(true)
        }
    }

现在您可以检查应用程序更新。

checkAppUpdateAvailability { (status) in
            //When status == true show popup.
        } onError: { (status) in
            // Handle error
        }

关于ios - 是否可以向 iOS 应用程序用户发送更新通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67364053/

相关文章:

ios - 使用 iOS 和 Swift 访问深度嵌套的 json 数据的最简单方法是什么?

ios - 检测 MTLTexture 是否为空白

iOS 7,在后台检查更新

ios - 如何在 iOS 中获取 Nsdate 格式的时间?

ios - 在 iOS/iPhone 上的 Ionic/Cordova/PhoneGap 应用程序中嵌入 YouTube 视频

ios - Storyboard和子类

swift - 复制 NSTableView 行变灰

objective-c - 通过 Objective-C/Cocoa 清空垃圾桶

ios - 为什么在iOS项目生成的XCTestCase中引入了Cocoa.h?

ios - 为什么 Realm addOrUpdateObject 会导致属性设置为 nil?