I have an app in which on viewController i have a simple webView and i am loading my website say https://mywebsite.com
Now i want to send device token to the same website as cookie but for some reason i could not access the deviceToken in viewDidLoad method.
Code is as per below of viewController.m
- (void)viewDidLoad {
     NSUserDefaults *deviceInfo = [NSUserDefaults standardUserDefaults];
     NSString *deviceID = [deviceInfo objectForKey:@"deviceToken"];
    [super viewDidLoad];
    NSURL *url=[NSURL URLWithString:@"http://staging.mywebsite.com"];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
    NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies: cookies];
    NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
    [cookieProperties setObject:@"deviceToken" forKey:NSHTTPCookieName];
    [cookieProperties setObject:deviceID forKey:NSHTTPCookieValue];
    [cookieProperties setObject:@"staging.mywebsite.com" forKey:NSHTTPCookieDomain];
    [cookieProperties setObject:@"staging.mywebsite.com" forKey:NSHTTPCookieOriginURL];
    [cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];
    NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
    [request setHTTPMethod:@"Post"];
    [request setHTTPShouldHandleCookies:YES];
    [request setAllHTTPHeaderFields:headers];
    [_webView loadRequest:request];
}
I have added following code in method didRegisterForRemoteNotificationsWithDeviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    NSString *strDevicetoken = [[NSString alloc]initWithFormat:@"%@",[[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""]];
    NSUserDefaults *deviceInfo = [NSUserDefaults standardUserDefaults];
    [deviceInfo setObject:strDevicetoken forKey:@"deviceToken"];
    [deviceInfo synchronize];
}
It still doesnt work on real device. What wrong am i doing here?
Thank you
 
     
    