Problema upload cu Dropbox API
  [ Ignoră ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

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!

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 1 ]
Avatar
RankRankRankRank
Sr. Member
Din: Timisoara
Macuser din: 18.04.08

Poate ajuta: http://forums.dropbox.com/topic.php?id=28703

 Semnătură 

MacBook Pro 17 “Santa Rosa” /6 GB RAM/500GB Momentus XT/GeForce 8600M GT (Lion)
iPhone 4 32Gb neverlocked | iPad 64+4G stock (iOS 5)

Mini Core Duo 1.83 / 2 GB RAM / 320 GB HDD (Snow)
Lampa iMac G4 17” 1.25 (Leo) + stand iGo
Powermac G4 | 1 Quicksilver + 2 Sawtooth (Tiger) | 2 x Apple Studio Display 15
Powerbook G4 12” Al, 1.5 GHz, 1.25 GB RAM (Leo)
iBook Clamshell Tangerine (9.2.2 + Panther) | Performa 5200 CD (8.1)

Profil
 
  [ Ignoră ]   [ # 2 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Nu merge nici asa,adica face upload doar daca ies din aplicatie si intru din nou,daca ies si atat nu face nimic in background….

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 3 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Am rezolvat problema,pun aici raspunsul in caz ca mai are cineva nevoie.
Problema era ca

[[self restClient] uploadFilefilename toPath:destPath withParentRev:nil fromPathpath]
nu avea timp sa faca upload-ul deoarece apelam imediat si
[[UIApplication sharedApplication] endBackgroundTasktaskIdentifier]

restClient are 2 metode delegate care sunt apelate doar pe thread-ul principal si acolo trebuia sa opresc executia din backgound prin:

[[UIApplication sharedApplication] endBackgroundTasktaskIdentifier]

Ca sa faca upload-ul pe thread-ul principal am inlocuit

dispatch_async(dispatch_get_global_queue(00), ^
cu
dispatch_async(dispatch_get_main_queue(), ^
 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 4 ]
RankRank
Jr. Member
Din: Bucuresti
Macuser din: 26.03.10

Starting with iOS 4, on 3rd-generation and newer iOS devices, multitasking is supported through seven background APIs:

- Background audio - application continues to run in the background as long as it is playing audio or video content
- Voice over IP - application is suspended when a phone call is not in progress
- Background location - application is notified of location changes
- Push notifications
- Local notifications - application schedules local notifications to be delivered at a predetermined time
- Task completion - application asks the system for extra time to complete a given task
- Fast app switching - application does not execute any code and may be removed from memory at any time

 Semnătură 

 iPhone 5 16GB black, iOS 7 beta 5
 MacBook Pro 15” Unibody, Late 2011 2,4 Ghz Intel Core i7, 8GB RAM, 128GB SSD, Radeon 6770 1GB, HiRes Display, OS X 10.8.3
 Thunderbolt Display

Profil
 
  [ Ignoră ]   [ # 5 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06
VladN - 28 Noiembrie 2011 12:17 PM

Starting with iOS 4, on 3rd-generation and newer iOS devices, multitasking is supported through seven background APIs:

- Background audio - application continues to run in the background as long as it is playing audio or video content
- Voice over IP - application is suspended when a phone call is not in progress
- Background location - application is notified of location changes
- Push notifications
- Local notifications - application schedules local notifications to be delivered at a predetermined time
- Task completion - application asks the system for extra time to complete a given task
- Fast app switching - application does not execute any code and may be removed from memory at any time

Si are e rostul acestui reply? smile

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil