菜鸟教程小白 发表于 2022-12-12 09:57:18

ios - NSHTTPCookieStorage 跨多个应用共享


                                            <p><p>如何在多个 iOS 应用程序之间共享 NSHTTPCookieStorage?我希望 MYAPP A 和 MYAPP B 使用相同的 cookie,这样我就可以轻松地在它们之间切换。</p>

<p>我在 <code>NSHTTPCookieStorage.h</code> 中找到了以下方法,但在 <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookieStorage_Class/" rel="noreferrer noopener nofollow">documentation</a> 中没有看到它.</p>

<pre><code>+ (NSHTTPCookieStorage *)sharedCookieStorageForGroupContainerIdentifier:(NSString *)identifier NS_AVAILABLE(10_11, 9_0);
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>为将来可能遇到此问题的其他 6 个人回答我自己的问题...</p>

<p>在我的研究中,我发现 <code>sharedCookieStorageForGroupContainerIdentifier:</code> 是专为 NSURLSession 设计的新功能,它允许您直接指定 <code>sharedHTTPCookieStorage</code> 以外的 cookie 存储。 </p>

<p>不幸的是,此功能不向后兼容 <code>NSURLConnection</code> 功能套件,如 <code>NSURLConnection</code> <a href="https://stackoverflow.com/questions/12022541/does-nsurlconnection-automatically-persist-cookies-sent-from-server" rel="noreferrer noopener nofollow">automatically persists its cookies to <code>sharedHTTPCookieStorage</code></a> ,并且此行为不能被覆盖。</p>

<p><strong>TL;DR:如果您想要自己的 Cookie 存储,请使用 NSURLSession。</strong> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - NSHTTPCookieStorage 跨多个应用共享,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34143129/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34143129/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - NSHTTPCookieStorage 跨多个应用共享