1

Create simple app with iOS 7 SDK but test app on both ios 6.x and 7.x and have same result. There are two ViewControllers – first MainScreen and second WebScreen

If i using NSURLConnection on MainScreen for my url, UIWebView not load content from same site.

In the MainScreen i load json as string from url

NSString *urlAsString = [NSString stringWithFormat:@"https://site.ws/api/index/index?method=get_count_new_orders&login=%@&password=%@", @"login", @"pass"];
NSURL *url = [[NSURL alloc] initWithString:urlAsString];
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:url] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

        if (error) {
            NSLog(@"error ::: %@", error);
        } else {

            NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            NSError *jserror = nil;            
            NSDictionary *JSON = nil;
            JSON = [NSJSONSerialization JSONObjectWithData: [string dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &jserror];

        }

    }];

On the second screen i try load page from same site:

NSString *stringUrl = [NSString stringWithFormat:@"https://reserva.ws/?lang=en"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:stringUrl]]];

and UIWebView load empty page.

But, if i comment [NSURLConnection sendAsynchronousRequest... on first screen, webview work fine.

George
  • 643
  • 9
  • 23

2 Answers2

1

I did small research with your problem and just copy your code to Xcode. What I did is:

  1. Create new project based on UINavigationController.
  2. In root vc I copied to viewDidLoad method your first sample of code.
  3. In second vc I copied to viewDidLoad method your second sample of code.
  4. Switching between vcs is based on pop/push vc from/to UINavigationController stack.
  5. Finally, everything looks fine.

After push second vc webview properly load url source webpage. I think you should use webview delegate property and set it to vc in which your webview object is. Then implement in it this vc method:

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

and check if you get error in case if your webview is not loaded. It should help you find source of your problems.

lwalukie
  • 89
  • 1
  • 10
  • thank you for so big research and testing, but the problem was in cookies. I think this is due bad authorization architecture on this web site. – George Nov 19 '13 at 04:09
1

After several days of deliberation i thought, that it might be due to cookies. I try before [self.webView loadRequest...

NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
    [storage deleteCookie:cookie];
}

And this fix problem.

George
  • 643
  • 9
  • 23