简体   繁体   中英

How to redirect Add to cart url page

I have an app for e-commerce and adding product id and quantity to addCart. Here i'm checking static sample value and passing this value to url for checking purpose. If this value matches i need redirect to add to cart url page. In browser it's working. But in mobile app when i click the button i need to check if value same i need to redirect. But it's not redirect.

    int i=2;

          NSString *post =[[NSString alloc] initWithFormat:@"password=%d",i];
         NSLog(@"PostData: %@",post);


         NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://serverurl.net/projects/AR/create_cart.php?id=%d",i]];

         NSLog(@"url is %@",url);


 NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

         NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

         NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
         [request setURL:url];
         [request setHTTPMethod:@"POST"];

         [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
         [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
         [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
         [request setHTTPBody:postData];

         //    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

         NSError *error = [[NSError alloc] init];
         NSHTTPURLResponse *response = nil;
         NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

         NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

         NSLog(@"Response code: %d", [response statusCode]);



         if ([responseData length]){

         NSLog(@"Response ==> %@", responseData);

         NSMutableDictionary *dict=[responseData JSONValue];


         NSLog(@"dict is %@",dict);

         NSInteger success = [(NSNumber *) [dict objectForKey:@"success"] integerValue];

         NSLog(@"%d",success);
         if(success == 1){



         }

It's not clear which e-commerce platform you're using. In case it happens to be Magento, here's how you can redirect users for signing in within an iOS app: https://github.com/mobstac/JustPaws/blob/master/MobstacShop/AuthViewController.m .

We faced the same problem and resolved it by capturing the WebView's response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM