开发者

xcode - ipad app. UIWebView Remember login info

开发者 https://www.devze.com 2022-12-31 00:55 出处:网络
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 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

精彩评论

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