Compare commits

...

4 Commits

Author SHA1 Message Date
127-Z3R0
9ed7faf2aa fix pbxproj-file due to rebase 2020-06-19 09:03:43 +02:00
127-Z3R0
722edad36d Add UpdatePopUp because Pfusch and its easier instead of rewriting ModalEntity
* still fixes needed with getting AppVersion from API
*
2020-06-19 09:03:43 +02:00
127-Z3R0
76a61b3daf Rewrite AppUpdater without UIKit-Elements 2020-06-19 09:03:43 +02:00
127-Z3R0
714c17ee30 Implement class AppUpdater for checking AppVerison in Appstore
* call Singleton AppUpdater if needed
* PopUp with UpdateInfo if AppStoreVersion is different to local
2020-06-19 09:03:43 +02:00
5 changed files with 161 additions and 6 deletions

View File

@ -49,11 +49,14 @@
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; };
C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; };
C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; };
C04E26D5249BEBB0003B9E51 /* AppUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E26D4249BEBB0003B9E51 /* AppUpdater.swift */; };
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05BB9C3247D890C00411249 /* SliderComponent.swift */; };
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05FAED52468559D0006AF2E /* SoundManager.swift */; };
C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A7246C0EA50022B228 /* LabelNode.swift */; };
C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A9246C114C0022B228 /* LabelComponent.swift */; };
C064E9AC246C151F0022B228 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9AB246C151F0022B228 /* Label.swift */; };
C06C71DD249BC74D00B2D63C /* AppUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06C71DC249BC74D00B2D63C /* AppUpdater.swift */; };
C06C71DF249BDADF00B2D63C /* UpdatePopUp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06C71DE249BDADF00B2D63C /* UpdatePopUp.swift */; };
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C099579B246C5E5C0016AA22 /* DataService.swift */; };
/* End PBXBuildFile section */
@ -115,11 +118,14 @@
ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; };
C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; };
C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; };
C04E26D4249BEBB0003B9E51 /* AppUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppUpdater.swift; path = GoldWars/AppUpdater.swift; sourceTree = SOURCE_ROOT; };
C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
C05FAED52468559D0006AF2E /* SoundManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundManager.swift; sourceTree = "<group>"; };
C064E9A7246C0EA50022B228 /* LabelNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelNode.swift; sourceTree = "<group>"; };
C064E9A9246C114C0022B228 /* LabelComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelComponent.swift; sourceTree = "<group>"; };
C064E9AB246C151F0022B228 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
C06C71DC249BC74D00B2D63C /* AppUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdater.swift; sourceTree = "<group>"; };
C06C71DE249BDADF00B2D63C /* UpdatePopUp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatePopUp.swift; sourceTree = "<group>"; };
C099579B246C5E5C0016AA22 /* DataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataService.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -149,6 +155,7 @@
110360EC244B101B008610AF /* GoldWarsTests */,
110360D0244B101A008610AF /* Products */,
9E78ACB4245C9A5300526FF7 /* Frameworks */,
C04E26D3249BEB73003B9E51 /* Recovered References */,
);
sourceTree = "<group>";
};
@ -185,6 +192,7 @@
C04783EF24685995004961FB /* SettingsScene.swift */,
3EAD889424801B6A0048A10A /* RoundTimer.swift */,
AB671B242494ECF0003FBE8D /* EloHelper.swift */,
C04E26D4249BEBB0003B9E51 /* AppUpdater.swift */,
);
path = GoldWars;
sourceTree = "<group>";
@ -230,6 +238,7 @@
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */,
3E6785412472CBEC007B9DE4 /* Way.swift */,
C064E9AB246C151F0022B228 /* Label.swift */,
C06C71DE249BDADF00B2D63C /* UpdatePopUp.swift */,
);
path = Entities;
sourceTree = "<group>";
@ -289,6 +298,14 @@
path = Map;
sourceTree = "<group>";
};
C04E26D3249BEB73003B9E51 /* Recovered References */ = {
isa = PBXGroup;
children = (
C06C71DC249BC74D00B2D63C /* AppUpdater.swift */,
);
name = "Recovered References";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -399,6 +416,7 @@
3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */,
9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */,
9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */,
C04E26D5249BEBB0003B9E51 /* AppUpdater.swift in Sources */,
3E6785422472CBEC007B9DE4 /* Way.swift in Sources */,
110360D9244B101A008610AF /* GameScene.swift in Sources */,
C04783F024685995004961FB /* SettingsScene.swift in Sources */,
@ -421,6 +439,7 @@
3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */,
3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */,
3E67854024728368007B9DE4 /* CElements.swift in Sources */,
C06C71DD249BC74D00B2D63C /* AppUpdater.swift in Sources */,
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
C064E9AC246C151F0022B228 /* Label.swift in Sources */,
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */,
@ -429,6 +448,7 @@
9E61EAC7249BB61A00334DDE /* SpinningLogo3DNode.swift in Sources */,
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
C06C71DF249BDADF00B2D63C /* UpdatePopUp.swift in Sources */,
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */,
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
@ -595,14 +615,14 @@
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = DDKFQG46BQ;
INFOPLIST_FILE = GoldWars/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -618,14 +638,14 @@
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = DDKFQG46BQ;
INFOPLIST_FILE = GoldWars/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

View File

@ -0,0 +1,83 @@
//
// AppUpdater.swift
// GoldWars
//
// Created by Tim Herbst on 18.06.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameKit
enum VersionError: Error {
case invalidBundleInfo, invalidResponse
}
class LookupResult: Decodable {
var results: [AppInfo]
}
class AppInfo: Decodable {
var version: String
var trackViewUrl: String
}
class AppUpdater: NSObject {
static var appStoreUrl = ""
static let appUpdaterInstance = AppUpdater()
var entityManager = EntityManager.menuEMInstance
private func getAppInfo(completion: @escaping (AppInfo?, Error?) -> Void) -> URLSessionTask? {
guard let identifier = Bundle.main.infoDictionary!["CFBundleIdentifier"] as? String,
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else {
DispatchQueue.main.async {
completion(nil, VersionError.invalidBundleInfo)
}
return nil
}
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
do {
if error != nil { throw error! }
guard let data = data else { throw VersionError.invalidResponse }
print("Data: ", data)
print("response: ", response!)
let result = try JSONDecoder().decode(LookupResult.self, from: data)
let dictionary = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
print("dictionary: ", dictionary)
guard let info = result.results.first else { throw VersionError.invalidResponse }
print("result: ", result)
completion(info, nil)
} catch {
completion(nil, error)
}
}
task.resume()
print("task***",task)
return task
}
func checkVersion() -> Bool {
let info = Bundle.main.infoDictionary
let currentVersion = info?["CFBundleShortVersionString"] as? String
var appStoreVersion: AppInfo
var isUpToDate = true
_ = getAppInfo{ (info, error) in
appStoreVersion = info!.version
print("info-version", info?.version)
if let error = error {
print("error: ",error)
}
}
print("currentVersion", currentVersion)
print("appStoreVersion", appStoreVersion)
if !(currentVersion == appStoreVersion) {
isUpToDate = false
}
print("isUptoDate", isUpToDate)
return isUpToDate
}
}

View File

@ -43,6 +43,11 @@ class EntityManager {
isModal = true
}
if let updateEntity = entity as? UpdatePopUp {
scene.addChild(updateEntity.background)
scene.addChild(updateEntity.message)
}
if let hudEntitiy = entity as? HUD {
scene.addChild(hudEntitiy.hostLabel)
scene.addChild(hudEntitiy.hostUnitsLabel)

View File

@ -0,0 +1,44 @@
//
// UpdatePopUp.swift
// GoldWars
//
// Created by Tim Herbst on 18.06.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameplayKit
class UpdatePopUp: GKEntity {
var entityManager = EntityManager.menuEMInstance
var background: SKSpriteNode
var message: SKLabelNode
init(anchorPoint: CGPoint) {
let texture = SKTexture(imageNamed: "ModalBackground")
background = SKSpriteNode(texture: texture, size: texture.size())
background.setScale(2.4)
background.position = anchorPoint
background.zPosition = 4
message = SKLabelNode(text: "Update erforderlich")
self.message.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 60)
self.message.fontName = "HelveticaNeue-Bold"
self.message.fontSize = 40
self.message.zPosition = 5
super.init()
addComponent(ButtonComponent(textureName: "yellow_button04", text: "zum Update", position: CGPoint(x: anchorPoint.x, y: anchorPoint.y - 105), isEnabled: true, onButtonPress: {
if let url = URL(string: AppUpdater.appStoreUrl), UIApplication.shared.canOpenURL(url) {
if #available(iOS 13.2, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}))
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -11,6 +11,7 @@ import SceneKit
class MenuScene: SKScene {
var entityManager = EntityManager.menuEMInstance
var appOutdated = false
override func sceneDidLoad() {
GameCenterManager.sharedInstance.menusc = self
@ -28,7 +29,7 @@ class MenuScene: SKScene {
} else {
if GameCenterManager.isAuthenticated {
GameCenterManager.sharedInstance.presentMatchmaker()
GameCenterManager.sharedInstance.presentGameCenter()
}else {
GameCenterManager.sharedInstance.authUser()
}
@ -70,8 +71,10 @@ class MenuScene: SKScene {
override func update(_ currentTime: TimeInterval) {
if entityManager.entities.count != 0 {
entityManager.getBackground()!.update(deltaTime: currentTime)
if !appOutdated {
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
}
}
if GameCenterManager.sharedInstance.initIsFinish {
self.loadScene(scene: GameCenterManager.sharedInstance.gameScene!)