I am using Monotouch to develop an iPhone App. I am using a web request to call a service that returns a cookie. My main aim is to be able to use the cookie as needed for web requests in various view controllers. I am assuming using the Shared Storage for the cookie is the way to go.
I have had a go at this and found the following hurdles:
- The HttpWebResponse has a cookie collection made up of System.Net.Cookie objects.
- The NSSharedStorage object only takes NSHttpCookie objects.
I haven't been able to figure out a way to turn a System.Net.Cookie object into an NSHttpCookie object. This is mainly because NSHttpCookie has only readonly properties and I am not sure how to create one using the constructors/static functions in C#.
So I really have two questions:
- Is inserting the cookie into shared storage the best way to achieve my aim?
- If so, how do I do this?
UPDATE:
Just to 开发者_开发百科clarify a little further. The answer here is doing the opposite of what I want to do.
I don't think there's such thing as a NSSharedStorage. Is NSHTTPCookieStorage what you mean? If so, this wouldn't work for you. As per the documentation: "Cookies are not shared among applications in iOS". There also isn't a quick way to do what you want. You'll have to do something like what is suggested in the link you provided in your update. i.e. create an extension method (or some kind of utility method) that does the conversion.
You will likely have to manage your own collection of System.Net.Cookies in your app.
精彩评论