I'm trying to make an IOS application and checking whether the user has logged in or not. When a user is not logged in, it should display a login form. Ive created multiple View Controllers and connected them with segue's. Than I used self.performSegueWithIdentifier("userLoggedOff", sender: self)
to activate the segue. But the error EXC_BAD_ACCESS
appears.
However, when I try to activate the same segue with the same code linked to a button, it all works. Really frustrating... Thnx for your help.
This is the full code. I used JSON to get the user's account info. It's probably not the way to do it, but i'm a beginner in xcode, swift and app-making in general.
import UIKit
import WebKit
class StartController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
checkLoginStatus_main()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func checkLoginStatus_main(){
let requestURL: NSURL = NSURL(string: "https://www.example.net/account/accountinfo.php")!
let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(urlRequest) {
(data, response, error) -> Void in
let httpResponse = response as! NSHTTPURLResponse
let statusCode = httpResponse.statusCode
if (statusCode == 200) {
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
if let accounts = json["account"] as? [[String: AnyObject]] {
for account in accounts {
if let status = account["status"] as? String {
if let name = account["name"] as? String {
if(status == "true"){
print("LoggedIn") // THIS WORKS
self.continueScanner()
} else {
print("LoggedOut") // THIS WORKS
self.continueLoginForm()
}
}
}
}
}
}catch {
print("Error with Json: \(error)")
}
}
}
task.resume()
}
func continueLoginForm(){
self.performSegueWithIdentifier("userLoggedOff", sender: self)
}
func continueScanner(){
self.performSegueWithIdentifier("userLoggedIn", sender: self)
}
}
This is the error: Screenshot of the error
Here is the full output:
LoggedOut
1 0x18771c654 <redacted>
2 0x1834bcfe4 <redacted>
3 0x1834b1e50 _os_once
4 0x1834ba728 pthread_once
5 0x1886a6d98 <redacted>
6 0x1886a6680 WebKitInitialize
7 0x188c4bfa0 <redacted>
8 0x100791a3c _dispatch_client_callout
9 0x1007928b4 dispatch_once_f
10 0x182ebcfc8 <redacted>
11 0x182ec38b8 <redacted>
12 0x182ecdd78 <redacted>
13 0x188f9c130 <redacted>
14 0x188f9c2cc <redacted>
15 0x188f9be9c <redacted>
16 0x188ca9ff4 <redacted>
17 0x188f9c154 <redacted>
18 0x188f9be9c <redacted>
19 0x188e780a0 <redacted>
20 0x188f9c154 <redacted>
21 0x188f9c2cc <redacted>
22 0x188f9be9c <redacted>
23 0x188e773d4 <redacted>
24 0x188d19140 <redacted>
25 0x188addfcc <redacted>
26 0x1889a07ec <redacted>
27 0x1889a0744 <redacted>
28 0x18928f504 <redacted>
29 0x188cfcca0 <redacted>
30 0x188d22a04 <redacted>
31 0x188d257a0 <redacted>