iosios9nsurlsessionios8-share-extensionios9.1

iOS Share Extension NSURLSession not working on iOS 9


So I have this iOS Share Extension for my app that sends a result to my server in didSelectPost() when the 'POST' button is clicked. It all works fine on simulator; the request is sent and I can see data packets going out in Charles.

On iOS 9, the Share Extension launches correctly, but the request is not sent in didSelectPost function.

I'm not sure if it's something wrong with my Share Extension or the NSURLSession.

The code -

- (void)didSelectPost {

    //Get session configuration
    NSString * const configName = @"com.xx.xxx";
    self.sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:configName];
    self.sessionConfiguration.sharedContainerIdentifier = @"group.xx.ShareURL";

    //Init NSURLSession
    self.session  = [NSURLSession sessionWithConfiguration:self.sessionConfiguration];
    NSURLRequest *request = [self postContentToService:self.shareUrl.absoluteString];

    //post request
    self.sessionTask = [self.session dataTaskWithRequest:request];

    //resume
    [self.sessionTask resume];

    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
}

Any help is appreciated.


Solution

  • Turns out I was using HTTP instead of HTTPS, and the ATP thing is blocking all my NSURLRequests, without ANY form of noticing.

    We pushed our server team to switch to allowing HTTPS and used HTTPS connections, everything works fine now.