SORU
10 Mayıs 2011, Salı


iOS: kurabiye el ile bir UİWebView için sharedHTTPCookieStorage kullanarak ayarlamak mümkün mü?

Webviews içinde düzgün bir şekilde kimlik doğrulaması için kimlik doğrulama tanımlama bilgisi gerektiren bir iOS uygulaması var. Bir istemci kimlik doğrulaması bilgileri zaten var gibi çerez ayarlamak için giden bir istek yapmak zorunda kalmadan bir kurabiye içinde bir iOS uygulama web görünümü ayarlamak için arıyorum.

post Bu UİWebView kurabiyelerin saklandığı bize gösteriyor.

Şu anda gizli bir web görünümü giden bir istek yapmak için yükleme yapıyorum ama basit bir çerez ayarı için harici bir istek yapmak için olmamasını tercih eder.

CEVAP
10 Mayıs 2011, Salı


Evet, bunu yapabilirsiniz. İlk olarak, applicationDidBecomeActive bu satırı ekleyin

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

Bu cookieAcceptPolicy uygulamalar arasında paylaşılan ve sizin bilginiz olmadan değiştirilebilir, uygulamayı çalıştıran her zaman ihtiyacınız Politikasını kabul etmek zorunda emin olmak istiyorum.

Daha sonra, çerez ayarlamak için:

NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"testCookie" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"someValue123456" forKey:NSHTTPCookieValue];
[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];

// set expiration to one month from now or any NSDate of your choosing
// this makes the cookie sessionless and it will persist across web sessions and app launches
/// if you want the cookie to be destroyed when your app exits, don't set this
[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

Bu tanımlama bilgisi adı testCookie ve değer someValue123456 ve www.example.com herhangi bir http isteği ile gönderilecektir.

Çerez ayarı için büyük bir uyarı için, lütfen sorumu buraya bakın!

NSHTTPCookieStorage state not saved on app exit. Any definitive knowledge/documentation out there?

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Art Food Kitty - Kelly Eddington

    Art Food Kit

    7 Kasım 2006
  • DONFANTASTICKYPESS

    DONFANTASTIC

    1 Temmuz 2007
  • Fraser Raft

    Fraser Raft

    9 Mart 2010