Vreau sa fac si eu upload la o poza in Dropbox cand aplicatia intra in background.
Daca rulez codul acesta cand aplicatia ruleaza normal merge bine.
[ code]
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@”%@”,NSStringFromSelector(_cmd));
__block UIBackgroundTaskIdentifier taskIdentifier;
taskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@“Background task ran out of time and was terminated.”);
[[UIApplication sharedApplication] endBackgroundTask: taskIdentifier];
}];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
if(self.image != nil)
{
NSLog(@“Image not nil”);
NSData *data = UIImageJPEGRepresentation(self.image, 1.0);
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent: @“img.jpg”];
if(path)
{
NSLog(@“Temporary directory OK”);
[data writeToFile: path atomically: YES];
}
else
{
NSLog(@“Saved in documents directory”);
path = [[self documentsDirectory] stringByAppendingPathComponent: @“img.jpg”];
[data writeToFile: path atomically: YES];
}
NSString *filename = @“img.jpg”;
NSString *destPath = @”/”;
[[self restClient] uploadFile: filename toPath:destPath withParentRev:nil fromPath: path];
}
NSLog(@“Finishing background task”);
[[UIApplication sharedApplication] endBackgroundTask: taskIdentifier];
});
}
// NSLog-urile arata asa:
// applicationDidEnterBackground:
// Image not nil
// Temporary directory OK
// Finishing background task
[/ code]
Din log-uri inteleg ca ultima metoda nu functioneaza: [self restClient] uploadFile: ....
Sau am gresit ceva cand am cerut timp de executie in background???
Multumesc anticipat!