Reputation: 311
As suggested from Apple I use finishandinvalidate method for NSURLSession
after that my app downloads each file.
Then the app must have download new update file but I don't reach to create new session.
Method to create session is this:
- (NSURLSession *)backgroundSession
{
NSString* sessionIdentifier=@"com.liuk.pf";
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:sessionIdentifier];
static NSURLSession *session = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
session = [NSURLSession sessionWithConfiguration:configuration
delegate:self delegateQueue:nil];
});
return session;
}
Upvotes: 2
Views: 1446
Reputation: 311
I resolved my problem. I was using this snippet suggested from Apple:
- (NSURLSession *)backgroundSession
{
/*
Using disptach_once here ensures that multiple background sessions with the same identifier are not created in this instance of the application. If you want to support multiple background sessions within a single process, you should create each session with its own identifier.
*/
static NSURLSession *session = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.example.apple-samplecode.SimpleBackgroundTransfer.BackgroundSession"];
session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
});
return session;
}
then my nsurlsession was static and created only once.
Now I create nsurlsession in init method of my nsobject
self = [super init];
if (self) {
NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.my.myapp"];
_session= [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
}
return self
Upvotes: 2