4

So I was just curious if the NSHTTPCookieStorage was persistent across applications, or local only to the current one. I want some cookies gathered in another app to be accessible in a search app. Is that how it works? Thanks!

PS: This is on the iPhone or iPad.

gabaum10
  • 3,769
  • 3
  • 48
  • 89

3 Answers3

6

For iOS, cookies are not shared across apps. Per Apple's documentation,

iOS Note: Cookies are not shared among applications in iOS.

Greg
  • 33,450
  • 15
  • 93
  • 100
  • Bah do you know of a way to make that happen? I tried saving the Cookie Storage into the UserPrefs but that doesn't seem to be working. I just need to make them global. I will remove them manually when I am done... – gabaum10 Sep 09 '10 at 13:18
  • If you are wanting to be able to share cookies gathered in any other app (including ones that you didn't write), I think you're out of luck. Even if you did manage to save the cookie storage globally, all other apps would need to do the same thing. Apple does not make it easy for apps to communicate; they are each in their own security sandbox. You could try registering a custom URL handler in your search app, and encode your data into a custom URL in the app that has the cookie (if you wrote that app). See http://j.mp/WjLQu for more info about this approach. – Greg Sep 09 '10 at 15:13
  • I figured out a workaround. Basically I just passed the creds through the URL scheme and recontacted the server to revalidate the credentials. Ugly and not super efficient, but it works and doesn't change the user experience at all. Thanks for the help! – gabaum10 Sep 09 '10 at 15:30
1

Created a workaround where I just pass the credentials to the new app and reconnect to server. Not very efficient, but passable until something better is found...

gabaum10
  • 3,769
  • 3
  • 48
  • 89
0

As Greg said, No. Each apps cookie storage is sandboxed.


A solution to the problem would be to use a SFSafariViewController, new to iOS9.

This implementation of WebViews are not sandboxed and have access to Safari's cookie storage. Meaning that two different apps could use this to both access the same cookies from Safari's cookie storage.

You would need to write a small web-service to handle writing the cookies and some sort of API to redirect cookie data back into the app.

Use this project as a starting point. It shows you how you can access Safari cookies from an app without the user having to do anything.

Hope this helps, Liam

Liam Ferris
  • 1,786
  • 2
  • 18
  • 38