是否可以向应用用户发送更新通知 iOS
Is it possible to send update notification to app users iOS
我有一个应用程序已经在应用程序商店上线了。是否可以在新更新可用时向所有用户发送更新通知?
应用程序版本比较的代码是:
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
}
我有一个应用程序已经在应用程序商店上线了。是否可以在新更新可用时向所有用户发送更新通知?
应用程序版本比较的代码是:
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
}