【问题标题】:iOS swift using alamofire to share cookie between app and share extensioniOS swift 使用 alamofire 在应用程序和共享扩展程序之间共享 cookie
【发布时间】:2016-01-14 15:49:19
【问题描述】:
我的应用程序使用 alamofire 向我的服务器发送请求,该服务器是节点 js,它使用护照保存用户的 cookie,从而让我知道每个请求的用户是谁。
我的问题是,现在我有一个共享扩展,它正在将图像发布到服务器,但没有用户的 cookie,从而使服务器认为用户没有登录。
我正在尝试找到解决此问题的方法。通过分享扩展发帖时,是否可以告诉 alamofire 使用应用程序的 cookie?
【问题讨论】:
标签:
ios
swift
cookies
alamofire
ios8-share-extension
【解决方案1】:
解决方案:
在我的主应用程序中,我使用 NSUserDefaults 保存了 cookie 的值,在我的共享扩展中,我使用以下方式发送了它:
let cookieValue = NSUserDefaults(suiteName: "group.com.xxx.xxx").objectForKey("cookieValue" as! String
mutableURLRequest.setValue("cookieName=\(cookieValue)", forHTTPHeaderField: "cookie")
我希望这会对某人有所帮助