@capgo/native-market 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/Plugin/Plugin.swift +21 -23
- package/package.json +1 -1
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -27,35 +27,33 @@ struct APIResult: Codable {
|
|
|
27
27
|
public class NativeMarket: CAPPlugin {
|
|
28
28
|
|
|
29
29
|
@objc func openStoreListing(_ call: CAPPluginCall) {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
guard let appId = call.getString("appId") else {
|
|
31
|
+
call.reject("appId is missing")
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
do {
|
|
35
|
+
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(appId)")
|
|
36
|
+
let data = try Data(contentsOf: url!)
|
|
37
|
+
let decoder = JSONDecoder()
|
|
38
|
+
let apps = try! decoder.decode(APIResult.self, from: data).apps
|
|
39
|
+
let urlStore = "itms-apps://itunes.apple.com/app/id\(apps[0].trackId)"
|
|
40
|
+
let appUrl = URL(string: urlStore)
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let apps = try! decoder.decode(APIResult.self, from: data).apps
|
|
38
|
-
let urlStore = "itms-apps://itunes.apple.com/app/id\(apps[0].trackId)"
|
|
39
|
-
let appUrl = URL(string: urlStore)
|
|
40
|
-
|
|
41
|
-
DispatchQueue.main.async {
|
|
42
|
-
if UIApplication.shared.canOpenURL(appUrl!) {
|
|
43
|
-
if #available(iOS 10.0, *) {
|
|
44
|
-
UIApplication.shared.open(appUrl!, options: [:]) { (success) in
|
|
45
|
-
call.resolve()
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
UIApplication.shared.openURL(appUrl!)
|
|
42
|
+
DispatchQueue.main.async {
|
|
43
|
+
if UIApplication.shared.canOpenURL(appUrl!) {
|
|
44
|
+
if #available(iOS 10.0, *) {
|
|
45
|
+
UIApplication.shared.open(appUrl!, options: [:]) { (success) in
|
|
49
46
|
call.resolve()
|
|
50
47
|
}
|
|
48
|
+
} else {
|
|
49
|
+
UIApplication.shared.openURL(appUrl!)
|
|
50
|
+
call.resolve()
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
} catch {
|
|
54
|
-
print("trackId cannot be found from appId")
|
|
55
|
-
call.reject("trackId cannot be found from appId")
|
|
56
53
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
54
|
+
} catch {
|
|
55
|
+
print("trackId cannot be found from appId")
|
|
56
|
+
call.reject("trackId cannot be found from appId")
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
|