My aim: to continue a web session across an app interruption (eg. incoming SMS that is read).
Approach A: I have tried to store the contents of a UIWebView in NSUserDefaults, like this:
NSData *webViewData = [NSKeyedArchiver archivedDataWithRootObject:webView];
[[NSUserDefaults standardUserDefaults] setObject:webViewData forKey:kDefaultsWebViewObjectKey];
and then restore it like:
NSData *dta = [[NSUserDefaults standardUserDefaults] objectForKey:kDefaultsWebViewObjectKey];
webView = [NSKeyedUnarchiver unarchiveObjectWithData:dta];
but that does not include the contents.
Approach B: I have also tried getting the contents of the UIWebView with:
NSString *content = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML;"];
then storing it, and retrieving it again, and then trying to set it in the UIWebView with:
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
but the innerHTML javascript is not returning the whole content.
Any ideas, suggestions, etc.?