简体   繁体   中英

iOS swift using alamofire to share cookie between app and share extension

My app using alamofire to send requests to my server which is node js that uses passport to save a cookie of the user thus allowing me to know for each request who is the user.

My problem is that now I have a share extension that are posting an image to the server but without the cookie of the user thus making the server think the user is not logged in.

I'm trying to find a way to solve this problem. Is there an option to tell alamofire to use the cookie of the app when posting via the share extension?

Solution:

In my main app I saved with NSUserDefaults the cookie's value and in my share extension I sent it using this:

let cookieValue = NSUserDefaults(suiteName: "group.com.xxx.xxx").objectForKey("cookieValue" as! String

mutableURLRequest.setValue("cookieName=\(cookieValue)", forHTTPHeaderField: "cookie")

I hope that this will help someone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM