I need to check that the user is still logged in properly, but the example in the docs for Swift is incorrect.
I have setStayLoggedIn set to true. Using the code results in an error as .try doesn’t exist. However replacing it with .tryblock crashes the program after a while sitting frozen.
Error;
unrecognized selector sent to instance 0x7ff6b942f6d0
Could not cast value of type ‘NSException’ (0x10a945358) to ‘Fault’ (0x106bb5740).
func validUserTokenSync() { Types.try({ () -> Void in var result = self.backendless.userService.isValidUserToken() //as NSNumber println("isValidUserToken (SYNC): \(result.boolValue)") }, catch: { (exception) -> Void in println("Server reported an error (SYNC): \(exception as Fault)") } ) }
My code…
func validUserTokenSync() -> Bool {
var valid: Bool = false
MMProgressHUD.showWithStatus("Connecting")
Types.tryblock({ () -> Void in
var result = self.backendless.userService.isValidUserToken()
debugPrint("isValidUserToken (SYNC): \(result.boolValue)")
valid = result.boolValue
MMProgressHUD.dismiss()
},
catchblock: { (exception) -> Void in
debugPrint("Server reported an error (SYNC): \(exception as! Fault)")
MMProgressHUD.dismissWithError("Please try later", title: "Server Error!", afterDelay: 4)
})
return valid
}