Last Updated: February 25, 2016
·
1.487K
· zordak

Debug Php calls sent from my iOS app (AFNetworking 2.0)

I'm actually working on an iOS app which calls a local php server.
I use AppCode as my iOS IDE and PhpStorm for .. Php :D

I wanted to debug my webservices call directly from PhpStorm. Usually it's easy with PhpStorm bookmarklets but here, no bookmarklet in AFNetworking.

So I decided to add a new Cookie in my NSHttpCookieStorage. (edit NSHTTPCookieDomain and NSHTTPCookiePath depending on your domain/website)

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *properties = @{
            NSHTTPCookieName : @"XDEBUG_SESSION",
            NSHTTPCookieValue : @"PHPSTORM",
            NSHTTPCookieDomain : @"server.local",
            NSHTTPCookiePath : @"/"
    };
    NSHTTPCookie *newCookie = [[NSHTTPCookie alloc] initWithProperties:properties];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:newCookie];

    [manager GET:@"http://server.local/index.php" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Response: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

Now, my http calls get caught by PhpStorm debugger !

Edit : You can also add this to your php.ini

xdebug.remote_autostart = 1