【问题标题】:WKProcessPool can be permanently stored using NSUserDefaults or something else?WKProcessPool 可以使用 NSUserDefaults 或其他东西永久存储吗?
【发布时间】:2015-10-11 17:11:20
【问题描述】:

感谢下面问题的回答,我弄清楚了如何通过使用 WKProcessPool 在多个 WKWebView 之间使用 Cookie。

Cookie sharing between multiple WKWebViews

然后我现在尝试使用 NSUserDefaults 永久存储 WKProcessPool 对象(我的单例对象)。

我遇到以下错误。 Attempt to insert non-property list object

所以我尝试通过 NSKeyedArchiver 将 WKProcessPool 对象转换为 NSData 来修复错误。 但是因为WKProcessPool没有实现encodeWithCoder:init:aDecoder所以做不到。

如何解决这个问题以永久存储 WKProcessPool 对象?

【问题讨论】:

    标签: ios xcode swift cookies wkwebview


    【解决方案1】:

    您需要为您的自定义对象实现NSCoding。这里是 Ray Wenderlich's tutorial


    编辑:

    我真的不知道WKProcessPool 是内置类,因为苹果没有在其中实现NSCoding,我什至看不到这个类的公共属性,所以即使你子类化它,你不知道要编码/解码哪些属性。

    您需要找到其他解决方案,而不是归档/归档对象。即使你使用 category 取得了一些成果,恐怕你也会得到预期的结果。

    【讨论】:

    • 你的意思是我应该创建一个WKProcessPool对象的子类并实现NSCoding?如果是这样,我以前尝试过,但我不知道该怎么做。如果可能,请向我展示您的实施概览。
    • extension WKProcessPool { convenience init(coder aDecoder: NSCoder) { aDecoder.decodeObject() self.init() } func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeObject(self) } } 我尝试通过extension实现NSCoding方法。但这每次都会重新创建新对象,即使它使用 initWithCoder: 初始化程序。如何正确实施?
    猜你喜欢
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2015-07-07
    • 2016-06-27
    • 1970-01-01
    相关资源
    最近更新 更多