2016-06-29 4 views
0

私はクラスメソッドの中で次の問題を抱えています。いくつかの長い実行プロセスを実行すると、渡されたパラメータの割り当てが解除されているようです。メソッドのパラメータが使用される前に割り当て解除されます

私はこのクラスの外からメソッドを呼び出しています。

+ (void)downloadVideoForExercise:(Exercise *)exercise{ 

    dispatch_queue_t serialQueue = dispatch_queue_create("com.blah.queue", DISPATCH_QUEUE_SERIAL); 

    dispatch_async(serialQueue, ^{ 

     [self isMaximumDownloadCapacityReached:^(BOOL success) { 
      if (success) { 
       return; 
      } 
     }]; 

     [self shouldDownloadVideoForExercise:exercise 
          andCompletionBlock:^(BOOL success) { 
           if (success == NO) { 
            return; 
           } 
          }]; 

     [NetworkManager downloadFileFromURL:exercise.videoServerURL 
          andSaveLocally:YES 
           andCompletion:^(BOOL success) { 

            dispatch_async(dispatch_get_main_queue(), ^{ 
             RLMRealm *realm = [RLMRealm defaultRealm]; 
             if (![realm inWriteTransaction]) { 
              [realm beginWriteTransaction]; 
             } 
             if (success) { 
              //save the new local link 
              NSString *videopath = [NetworkManager getVideoLocalURLFromServerURLForExercise:exercise.videoServerURL]; 
              exercise.videoLocalURL = videopath; 
              //change flag for ExerciseVideoDownloadState 
              exercise.videoDownloadState = isDownloadCompleted; 
             }else{ 
              //change flag for ExerciseVideoDownloadState 
              exercise.videoDownloadState = isNotDownloaded; 
             } 
             if ([realm inWriteTransaction]) { 
              [realm commitWriteTransaction]; 
             } 
            }); 

           }]; 

    }); 

} 

は、私はすでに__strongや__block ではなく、成功せずに渡されたパラメータを使用して考えました。 ご協力いただきありがとうございます。

+1

どのパラメータを参照していますか?それは助けになるだろう。 –

+0

私はメソッドに渡されたパラメータを参照しています。これらの場合はオブジェクトです: '(エクササイズ*)エクササイズ' –

+1

「解約されたようです」とはどういう意味ですか? – newacct

答えて

0

問題は、私が使用しているライブラリRealmによって生成されました。 問題は、オブジェクトへのすべての変更が、いくつかのカスタムメモリハンドルを行うC++クラスのハンドルであることでした。オブジェクトを呼び出すときには、nil値ではなくポインタであったC++オブジェクト仕事をしている。そうすることで問題を回避しました:

- (void)downloadVideoForExercise:(Exercise *)exercise{ 
    if (!serialQueue) { 
     serialQueue = dispatch_queue_create("com.blah.queue", DISPATCH_QUEUE_SERIAL); 
    } 

    NSString *url = exercise.videoServerURL; 

    dispatch_async(serialQueue, ^{ 

     [self isMaximumDownloadCapacityReached:^(BOOL success) { 
      if (success) { 
       return; 
      } 
     }]; 

     [self shouldDownloadVideoForExercise:exercise 
          andCompletionBlock:^(BOOL success) { 
           if (success == NO) { 
            return; 
           } 
          }]; 

     [self downloadFileFromURL:url 
          andSaveLocally:YES 
           andCompletion:^(BOOL success, NSString *localURL) { 

            dispatch_async(dispatch_get_main_queue(), ^{ 
             RLMRealm *realm = [RLMRealm defaultRealm]; 
             if (![realm inWriteTransaction]) { 
              [realm beginWriteTransaction]; 
             } 
             if (success) { 
              //save the new local link 
              NSString *videopath = [self getVideoLocalURLFromServerURLForExercise:exercise.videoServerURL]; 
              exercise.videoLocalURL = videopath; 
              //change flag for ExerciseVideoDownloadState 
              exercise.videoDownloadState = isDownloadCompleted; 
             }else{ 
              //change flag for ExerciseVideoDownloadState 
              exercise.videoDownloadState = isNotDownloaded; 
             } 
             if ([realm inWriteTransaction]) { 
              [realm commitWriteTransaction]; 
             } 
            }); 

           }]; 

    }); 

} 
関連する問題