开发者

xcode - ipad app. UIWebView Remember login info

I'm working on an application to run base camps website only.

I need it to work when you login and press "Remember me on this computer"

I'm not sure h开发者_运维百科ow to set it up to actually remember your login and keep you logged in when you come back to the app.

Is there a way to 'save' the state of the application when you quite it and come back to what you were doing?

Here is an image of the login form on the website used in the application.

http://arikburns.com/forums/fn/IMG_0005.PNG

Thanks.


If your web application uses url sessions, you can save your current URL using the webview delegate:

- (void)webViewDidFinishLoad:(UIWebView *)myWebView {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setObject:myWebView.request.URL.absoluteString forKey:@"lastUrl"];
    [prefs synchronize];
}

… and load it from the preferences later again when the viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: [prefs objectForKey:@"lastUrl"]]]];
}

You can also access the cookies using javascript, if you need to save and set them:

NSString *myCookies = [[myWebView stringByEvaluatingJavaScriptFromString:@"document.cookie"] copy];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜