开发者

iOS - Log in via Webservice

开发者 https://www.devze.com 2023-04-10 05:14 出处:网络
In my app, I have a splitview containing data aquired via a WS call. To recieve this data, the user must be logged in. To log in, I modally present a login screen when the applic开发者_开发技巧ation l

In my app, I have a splitview containing data aquired via a WS call. To recieve this data, the user must be logged in. To log in, I modally present a login screen when the applic开发者_开发技巧ation loads. After entering the credentials, I print out the result from a isLoggedIn WS call. This all works fine and dandy.

The problem is that while in the login screen, the isLoggedIn returns that the user is succesfully logged in (including session ID), but when I dismiss the login screen, every WS call fails because the user is not logged in. The session ID's match and the WS recieves the calls, but the iPad seems to remove the session upon dismissing the login screen. This results in the following logs:

2011-09-30 09:37:05.335 DSApp[366:707] url call: http://***/ipadwebservice.asmx/authenticateUser?username=user&password=pass
2011-09-30 09:37:05.508 DSApp[366:707] Call succesful. 
2011-09-30 09:37:05.509 DSApp[366:707] Logged in successfully.
2011-09-30 09:37:05.511 DSApp[366:707] Dismissing LoginView.
2011-09-30 09:37:08.644 DSApp[366:7d0f] url call: http://***/ipadwebservice.asmx/getChildFoldersByFolderID?folderId=-1
2011-09-30 09:37:08.649 DSApp[366:7d0f] Call failed. (Reason: User not logged in!)
2011-09-30 09:37:09.493 DSApp[366:7d0f] url call: http://***/ipadwebservice.asmx/getDocumentsByFolderId?folderId=-1
2011-09-30 09:37:09.497 DSApp[366:7d0f] Call failed. (Reason: User not logged in!)

Another weird thing is that when I hardcode the login details and call in the applicationDidFinishLaunching method, everything works perfectly and all WS calls are recieved succesfully.

Bueno:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
# warning hardcode login
    [WebservicesController authenticateUserWithName:@"user" andPassword:@"pass"];

    self.window.rootViewController = self.splitViewController;

    //login
    LoginViewController *loginView = [LoginViewController new];
    loginView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self.splitViewController presentModalViewController:loginView animated:YES];
    [loginView release];
}

No bueno:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    # warning hardcode login
        //[WebservicesController authenticateUserWithName:@"user" andPassword:@"pass"];

        self.window.rootViewController = self.splitViewController;

        //login
        LoginViewController *loginView = [LoginViewController new];
        loginView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self.splitViewController presentModalViewController:loginView animated:YES];
        [loginView release];
    }


Your code exemple is not really clear, but did you create your instance of WebservicesController in you login controller ?

Cause if you release your login controller, your WebservicesController is probably release and so is the authentication...

And that should explain why its working in the appDelegate


The session ID's match and the WS recieves the calls, but the iPad seems to remove the session upon dismissing the login screen.

Is there any piece of code which can "remove" the session? If so put a breakpoint there and see if it is being called.

Otherwise, my guess is that after all, you are not sending the session ID correctly with the request.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号