Commit 883a1faf authored by shigemi miura's avatar shigemi miura

バージョンアップ処理

parent 41876a5c
......@@ -9,7 +9,6 @@ import Foundation
class AppVersionModel: ObservableObject {
private var serverSession = ServerSession()
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
func start() {
......@@ -25,7 +24,9 @@ class AppVersionModel: ObservableObject {
let json = try JSONSerialization.jsonObject(with: appData, options: [.allowFragments]) as? [String: Any]
guard let result = (json?["results"] as? [Any])?.first as? [String: Any],
let storeVersion = result["version"] as? String else { return }
print(debug: "\(storeVersion)")
if let app = self.appVersion as? String {
SharingData.my.isUpDate = storeVersion.versionCompare(app) == .orderedDescending
}
} catch {
print(error)
}
......@@ -44,27 +45,23 @@ class AppVersionModel: ObservableObject {
}
serverSession.getJson(req_url, completion: completion)
}
}
// func appVersionCheck() {
// guard let info = Bundle.main.infoDictionary,
// let appVersion = info["CFBundleShortVersionString"] as? String,
// let identifier = info["CFBundleIdentifier"] as? String,
// let url = URL(string: "https://itunes.apple.com/lookup?bundleId=\(identifier)") else { return }
//
// let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
// guard let data = data else { return }
// do {
// let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any]
// guard let result = (json?["results"] as? [Any])?.first as? [String: Any],
// let storeVersion = result["version"] as? String else { return }
//
// if appVersion != storeVersion {
// // appVersion と storeVersion が異なっている時に実行したい処理を記述
// }
// } catch let error {
// print(error)
// }
// }
// task.resume()
// }
/**
* Version番号比較
* メジャーバージョン・マイナーバージョン・リビジョンバージョン
* マイナーバージョン以上が変更された場合
*/
extension String {
func versionCompare(_ otherVersion: String) -> ComparisonResult {
let delimiter = "."
var versionComponents = self.components(separatedBy: delimiter)
var otherComponents = otherVersion.components(separatedBy: delimiter)
versionComponents[2] = "0"
otherComponents[2] = "0"
return versionComponents.joined(separator: delimiter)
.compare(otherComponents.joined(separator: delimiter), options: .numeric)
}
}
......@@ -29,10 +29,10 @@ enum HttpRequestType : String {
case GetManualUrl = "https://ssv-canary-web.azurewebsites.net/api/constantdata/manual?filter=SailAssist"
case ContactPage = "https://www.jmarinecloud.com/eng/contact.php?type=ssv_mobile"
case ApachLicens = "https://raw.githubusercontent.com/Azure/azure-notificationhubs-ios/main/LICENSE"
case AppStore = "https://apps.apple.com/jp/app/ssv-mobile/id1434022656"
case AppInfo = "https://itunes.apple.com/lookup?bundleId=com.jrc.tacmi"
// case AppStore = "https://apps.apple.com/jp/app/sail-assist/id6473762428"
// case AppInfo = "https://itunes.apple.com/lookup?bundleId=com.jrc.sailassist"
// case AppStore = "https://apps.apple.com/jp/app/ssv-mobile/id1434022656"
// case AppInfo = "https://itunes.apple.com/lookup?bundleId=com.jrc.tacmi"
case AppStore = "https://apps.apple.com/jp/app/sail-assist/id6473762428"
case AppInfo = "https://itunes.apple.com/lookup?bundleId=com.jrc.sailassist"
}
#elseif QC
enum HttpRequestType : String {
......
......@@ -83,6 +83,8 @@ struct MapTaskView: View {
.frame(height: 55)
}
.onAppear{
let appVersionModel = AppVersionModel()
appVersionModel.start()
EcaCoordinatesTable().setEcaData()
}
.alert("", isPresented: $eca.isShowEcaAlert) {
......
......@@ -35,6 +35,13 @@ struct MenuGpsSelectView: View {
Spacer()
}
.background(ColorSet.BackgroundPrimary.color)
.onAppear{
if Preferences.LocationType == 0{
selected = .Mobile
}else{
selected = .Cloud
}
}
}
struct SelectContentView: View {
......@@ -76,7 +83,6 @@ struct MenuGpsSelectView: View {
}
}
}
}
#Preview {
......
......@@ -28,7 +28,7 @@ class SharingData{
@Published var shipName: String = ""
@Published var imo: Int = 0
@Published var mmsi: Int = 0
@Published var company: String = "JRC Co.,Ltd"
@Published var isUpDate: Bool = false
@Published var ecaStatus: EcaState?
......
......@@ -23,7 +23,6 @@ enum Tab: String, CaseIterable{
struct MainTabView: View {
@EnvironmentObject var selectedTabModel: SelectedTabModel
@EnvironmentObject private var sceneDelegate: SceneDelegate
@ObservedObject var my = SharingData.my
@State var isSignout = false
@State var isLogin = false
......@@ -69,6 +68,8 @@ struct MainTabView: View {
struct CustomTabBar: View {
@EnvironmentObject private var selectedTabModel: SelectedTabModel
@State var isLocationAlert = false
@Environment(\.openURL) var openURL
@ObservedObject var my = SharingData.my
var body: some View {
VStack(spacing: 0){
......@@ -116,6 +117,13 @@ struct CustomTabBar: View {
} message: {
Text("To use ECA,set the permission to use location information to ALWAYS.")
}
.alert("Update", isPresented: $my.isUpDate) {
Button("Go to app page"){
openURL(URL(string: HttpRequestType.AppStore.rawValue)!)
}
} message: {
Text("A new version of this app is available.")
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment