Why I can't save WKWebView to [NSUserDefaults standardUserDefaults]?

前端 未结 4 660
长情又很酷
长情又很酷 2020-12-31 12:39
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

[prefs setObject:self.webView forKey:@\"webView\"];

The code above is made to save

4条回答
  •  再見小時候
    2020-12-31 13:10

    you can only store certain types of objects in NSUserDefaults, namely

    NSArray
    NSData
    NSDate
    NSDictionary
    NSNumber
    NSString
    

    (you cant bypass this by putting your webview inside an NSArray)

    what you could do is store relevant information about the webview in an NSDictionary that would allow you to be able to get your webview back into its current state when loading from the NSUserDefaults

    you can refer to the documentation for more details

提交回复
热议问题