LoginSignup
46
44

More than 5 years have passed since last update.

UIWebViewにCookieを設定する方法

Posted at

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]を使って設定することが出来ます。
引数に渡すcookieの生成方法などはサンプルを参照。

SetCookieSample

@implementation SetCookieSample

- (void)cookieSample:(NSString *)cookieName cookieValue:(NSString *)cookieValue cookieDomain:(NSString *)cookieDomain {
    NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:
            cookieName, NSHTTPCookieName,
            cookieValue, NSHTTPCookieValue,
            cookieDomain, NSHTTPCookieDomain,
            @"/", NSHTTPCookiePath,
            [NSDate distantFuture], NSHTTPCookieExpires,
            nil]];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}

@end

46
44
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
44