2016-07-25 3 views
0

J'ai récemment revisité mon application qui a été construite pour iOS 8.4 et qui est maintenant mise à jour vers 9.3. Il fonctionnait très bien les premières fois je l'ai couru, mais se brise maintenant sur tous ouverts, sur chaque simulateur avec l'erreur: EXC_BAD_ACCESS (code = 50)Crash iOS sur Démarrer Tâche de fond

-(void)beginBackgroundUpdateTask 
{ 
    if (self.backgroundTaskAgent == UIBackgroundTaskInvalid) 
    { 
    self.backgroundTaskAgent = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) { 
     [self endBackgroundUpdateTask]; 
    }]; 
    } 
} 
-(void)endBackgroundUpdateTask 
{ 
    if (self.backgroundTaskAgent != UIBackgroundTaskInvalid) 
    { 
     [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskAgent]; 
     self.backgroundTaskAgent = UIBackgroundTaskInvalid; 
    } 
} 

L'accident se produit dans la méthode top avec beginBackgroundTaskWithExpirationHandler. Je n'ai jamais eu cette erreur auparavant et je ne trouve aucune solution pour moi-même ou sur SO.

Répondre

0

Essayez comme ça,

-(void)beginBackgroundUpdateTask 
{ 
    self.backgroundTaskAgent == UIBackgroundTaskInvalid 

    self.backgroundTaskAgent = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) { 
    [self endBackgroundUpdateTask]; 
}]; 

} 
-(void)endBackgroundUpdateTask 
{ 

    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskAgent]; 
    self.backgroundTaskAgent = UIBackgroundTaskInvalid; 

} 
+0

Alors, que l'erreur ne McKee faire? – SeanChense

+0

Fantastique, ça l'a beaucoup aidé. Qu'est-ce qui causait l'erreur alors? –

+0

votre tâche bg doit être invalide avant de recommencer! – Lion