0

I have two targets in my workspace an iOS App (Bundle id: com.gotit.iphone.gotit, App Group: group.com.gotit.iphone.gotit) and an share extension (Bundle id: group.com.gotit.iphone.gotit.Got-it, App Group: group.com.gotit.iphone.gotit).

I can use my share extension without problem but sometimes (not all the time) when I directly come back to my iOS app I have this error and my app crashes :

Attempted to create a task in a session that has been invalidated
2015-07-22 16:31:21.999 iphone[6095:717111] *** Assertion failure in -[BDBOAuth1SessionManager setDelegate:forTask:], /Users/gautier/Documents/Dev/gotit/iOS/iPhone/trunk/iphone/Pods/AFNetworking/AFNetworking/AFURLSessionManager.m:449
2015-07-22 16:31:22.001 iphone[6095:717111] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: task'
*** First throw call stack:
(0x1865a02d8 0x1982140e4 0x1865a0198 0x187454ed4 0x100547340 0x1005476d8 0x100549190 0x100522084 0x100520a38 0x1000c94a8 0x1000d9f9c 0x1000d9d8c 0x18b02ff08 0x18b1bb2bc 0x18b0cde84 0x18b0cdc50 0x18b0cdbd0 0x18b0156f4 0x18a951db8 0x18a94c820 0x18a94c6c4 0x18a94be58 0x18a94bbd8 0x18a945300 0x1865582a4 0x186555230 0x186555610 0x1864812d4 0x18fedf6fc 0x18b07ef40 0x1000d6fac 0x1988bea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

I use AFNetworking (with BDBOAuth1SessionManager) and this is how I create my networkManager :

+ (instancetype)create {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[[self class] alloc] init];
    });
    return _sharedClient;
}

+ (instancetype)sharedClient {
    if (!_sharedClient) {
        [GotItClient create];
    }
    return _sharedClient;
}

- (id)init {
    self = [super init];
    if (self) {
        NSURL *baseURL = [NSURL URLWithString:kSCGotItClientAPIURL];
        NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"group.com.gotit.iphone.gotit"];
        sessionConfiguration.sharedContainerIdentifier = @"group.com.gotit.iphone.gotit";

        _networkManager = [[BDBOAuth1SessionManager alloc]
                           initWithBaseURL:baseURL
                           sessionConfiguration:sessionConfiguration
                           consumerKey:kSCGotItClientKey
                           consumerSecret:kSCGotItClientSecret
                           shareDefaultGroupId:@"group.com.gotit.iphone.gotit"];
        _networkManager.responseSerializer = [[AFJSONResponseSerializer alloc] init];
        //4 operations at same time
        [[_networkManager operationQueue] setMaxConcurrentOperationCount:20];
    }
    return self;
}

Tell me if you need more code

Gautier
  • 47
  • 1
  • 13
  • It looks like the session manager is creating a nil task. Possibly due to you passing an invalid `NSURLRequest` to it? Hard to say without seeing more code. – dan Jul 22 '15 at 15:25
  • when I wait 2 seconds every think works fine, the NSURLRequest is valid. – Gautier Jul 23 '15 at 07:37
  • I encountered the same problem! You mean you fix it by doing nothing. Is it? – Neal.Marlin May 03 '17 at 09:02

0 Answers0