Files
Woka_Native_iOS/WOKA/Games/Controller/GamesWebViewVC.swift
BilalKhanWDI 5cf02c5aae - Completed click count in sidebar
- Handled optional gender type
- Handled optional gender in profile
- Remaining MyListVC changes
2024-08-13 20:02:41 +05:30

123 lines
4.0 KiB
Swift

//
// GamesWebViewVC.swift
// WOKA
//
// Created by MacBook Pro on 04/07/24.
//
import UIKit
import WebKit
class GamesWebViewVC: UIViewController, WKNavigationDelegate,UIGestureRecognizerDelegate {
var url : String?
var orientation : ScreenOrientation?
var count = 0
var postID : Int?
@IBOutlet weak var clickView: UIView!
@IBOutlet weak var webView: WKWebView!
deinit{
// print("Deinit Game")
if let postID = self.postID{
PersistentStorage.shared.addGamesCount(postID: postID,count: count)
}
}
override func viewDidLoad() {
super.viewDidLoad()
if let orientation, orientation == .landscape{
appDelegate.deviceOrientation = .landscapeRight
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
// rotateToLandsScapeDevice()
}
guard let url else{return}
let authUrl = url + "?tk=" + AuthFunc.shareInstance.getAccessToken()
let link = URL(string: authUrl)!
let request = URLRequest(url: link)
webView.load(request)
let tap = UITapGestureRecognizer(target: self, action: #selector(didTapMethod))
tap.numberOfTapsRequired = 1
tap.delegate = self
// Add the gesture recognizer to the web view
clickView.addGestureRecognizer(tap)
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
@objc func didTapMethod(){
count += 1
print(count)
}
@IBAction func backBtnTapped(_ sender: UIButton) {
if let postID = self.postID{
PersistentStorage.shared.addOthersCount()
}
let sb = UIStoryboard(name: K.StoryBoard.customAlerts, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.CustomAlerts.yesNoAlertVC) as! YesNoAlertVC
vcPush.mainTitleText = "Warning"
vcPush.contentLabel = "Clicking \"OK\" will exit you from the game. Are you sure you want to proceed?"
vcPush.yesBtnText = "OK"
vcPush.noBtnText = "Cancel"
vcPush.onDoneBlock = { [weak self] mode in
guard let self else{return}
switch mode{
case .yes:
if orientation == .landscape{
appDelegate.deviceOrientation = .portrait
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}else{
Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false) { _ in
self.dismiss(animated: true)
}
}
case .no:
if let postID = self.postID{
PersistentStorage.shared.addGamesCount(postID: postID)
}
print("no")
}
}
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
self.present(vcPush, animated: true)
}
// MARK: - Handle Screen Transition
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil) { _ in
self.checkOrientation()
}
}
private func checkOrientation() {
let isPortrait = UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height
if isPortrait {
// print("Device is in portrait mode")
Timer.scheduledTimer(withTimeInterval: 0.8, repeats: false) { _ in
self.dismiss(animated: true)
}
} else {
print("Device is in landscape mode")
}
}
}