@capgo/native-market 1.0.8 → 1.0.10
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/README.md +5 -1
- package/ios/Plugin/Plugin.swift +37 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Capacitor Native Market Plugin
|
|
2
2
|
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/">Check out: Capgo — Instant updates for capacitor</a></h2>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
4
8
|
Capacitor community plugin for native market for Play Store/App Store.
|
|
5
9
|
|
|
6
10
|
## Maintainers
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
3
|
|
|
4
|
+
struct APIResult: Codable {
|
|
5
|
+
struct App: Codable {
|
|
6
|
+
let trackId: Int
|
|
7
|
+
|
|
8
|
+
enum CodingKeys : String, CodingKey {
|
|
9
|
+
case trackId
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let resultCount: Int
|
|
14
|
+
let apps: [App]
|
|
15
|
+
|
|
16
|
+
enum CodingKeys : String, CodingKey {
|
|
17
|
+
case resultCount
|
|
18
|
+
case apps = "results"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
/**
|
|
5
23
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
24
|
* here: https://capacitor.ionicframework.com/docs/plugins/ios
|
|
@@ -12,20 +30,29 @@ public class NativeMarket: CAPPlugin {
|
|
|
12
30
|
if call.hasOption("appId") {
|
|
13
31
|
let appId = call.getString("appId")
|
|
14
32
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
do {
|
|
34
|
+
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(appId)")
|
|
35
|
+
let data = try Data(contentsOf: url!)
|
|
36
|
+
let decoder = JSONDecoder()
|
|
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!)
|
|
22
49
|
call.resolve()
|
|
23
50
|
}
|
|
24
|
-
} else {
|
|
25
|
-
UIApplication.shared.openURL(appUrl!)
|
|
26
|
-
call.resolve()
|
|
27
51
|
}
|
|
28
52
|
}
|
|
53
|
+
} catch {
|
|
54
|
+
print("trackId cannot be found from appId")
|
|
55
|
+
call.reject("trackId cannot be found from appId")
|
|
29
56
|
}
|
|
30
57
|
} else {
|
|
31
58
|
call.reject("appId is missing")
|