main.swift中代码:
import Foundationimport UIKitUIApplicationMain( Commandline.argc,UnsafeMutableRawPointer(Commandline.unsafeArgv) .bindMemory( to: UnsafeMutablePointer<Int8>.self,capacity: Int(Commandline.argc)),NsstringFromClass(MyApplication.self),NsstringFromClass(AppDelegate.self))UIApplication.swiftimport Foundationimport UIKit@objc(MyApplication)class MyApplication: UIApplication { overrIDe init(){ super.init(); if(_timer == nil){ _timer = Timer.scheduledTimer( timeInterval: TimeInterval(_IDleSecondsTriggerlogout),target: self,selector: #selector(MyApplication.dosomething),userInfo: nil,repeats: true) } } let _IDleSecondsTriggerlogout:Int = 8 * 60; // 8 mins,same with androID var _timer:Timer? = nil; overrIDe func sendEvent(_ event: UIEvent) { // Ignore .Motion and .RemoteControl event simply everything else then .touches if event.type != .touches { super.sendEvent(event) return } // .touches only var restartTimer = true if let touches = event.alltouches { // At least one touch in progress? Do not restart timer,just invalIDate it for touch in touches.enumerated() { if touch.element.phase != .cancelled && touch.element.phase != .ended { restartTimer = false break } } } if restartTimer { // touches ended || cancelled,restart timer resetTimer() } else { // touches in progress - !ended,!cancelled,just invalIDate it //print("touches in progress. InvalIDate timer") } super.sendEvent(event) } func resetTimer() { _timer?.invalIDate() _timer = Timer.scheduledTimer( timeInterval: TimeInterval(_IDleSecondsTriggerlogout),repeats: true) } func dosomething(){ print("time up,logout and clear session 1"); ServiceProxy.httpMeta.RefreshToken = ""; ServiceProxy.httpMeta.Token = ""; ServiceProxy.httpMeta.Username = ""; print("time up,logout and clear session 2"); let topVC = topVIEwController() print("time up,logout and clear session 3"); let storyBoard : UIStoryboard = UIStoryboard(name: "Main",bundle:nil) print("time up,logout and clear session 4"); let nextVIEwController = storyBoard.instantiateVIEwController(withIDentifIEr: "LoginVC") as! LoginVC print("time up,logout and clear session 5"); topVC?.present(nextVIEwController,animated:true,completion:nil) print("time up,logout and clear session 6"); } func topVIEwController(controller: UIVIEwController? = UIApplication.shared.keyWindow?.rootVIEwController) -> UIVIEwController? { if let navigationController = controller as? UINavigationController { return topVIEwController(controller: navigationController.visibleVIEwController) } if let tabController = controller as? UITabbarController { if let selected = tabController.selectedVIEwController { return topVIEwController(controller: selected) } } if let presented = controller?.presentedVIEwController { return topVIEwController(controller: presented) } return controller } }
AppDelegate.swift中代码(注释掉UIApplicationMain)
//@UIApplicationMain
info.pList中代码:
<key>Principal class</key> <string>MyApplication</string>总结
以上是内存溢出为你收集整理的Swift 无 *** 作时自动登出全部内容,希望文章能够帮你解决Swift 无 *** 作时自动登出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)