Add UpdatePopUp because Pfusch and its easier instead of rewriting ModalEntity
* still fixes needed with getting AppVersion from API *
This commit is contained in:
parent
76a61b3daf
commit
722edad36d
@ -54,6 +54,8 @@
|
||||
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 */
|
||||
|
||||
@ -120,6 +122,8 @@
|
||||
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 */
|
||||
|
||||
@ -231,6 +235,7 @@
|
||||
9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */,
|
||||
3E6785412472CBEC007B9DE4 /* Way.swift */,
|
||||
C064E9AB246C151F0022B228 /* Label.swift */,
|
||||
C06C71DE249BDADF00B2D63C /* UpdatePopUp.swift */,
|
||||
);
|
||||
path = Entities;
|
||||
sourceTree = "<group>";
|
||||
@ -422,6 +427,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 */,
|
||||
@ -430,6 +436,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 */,
|
||||
|
83
GoldWars/GoldWars/AppUpdater.swift
Normal file
83
GoldWars/GoldWars/AppUpdater.swift
Normal 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
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
44
GoldWars/GoldWars/Entities/UpdatePopUp.swift
Normal file
44
GoldWars/GoldWars/Entities/UpdatePopUp.swift
Normal 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")
|
||||
}
|
||||
}
|
@ -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!)
|
||||
|
Loading…
Reference in New Issue
Block a user