NSNotification はメイン スレッド以外のスレッドでセレクターを呼び出すため、その通知に応じて UIView やその他のインターフェイス要素に加えた変更は、反映されるまでに時間がかかることがよくあります。これは、メイン スレッドがビジー状態の場合に最も深刻です (私の場合はよくあります!)。
「performSelectorOnMainThread:」を呼び出すことで問題を解決できます。これは本当にベストプラクティスですか?
- (void) gotMovieSaveFinishNotication: (NSNotification *) not {
NSURL *exportMovieURL = (NSURL *) [not object];
//saving the composed video to the photos album
ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease];
if(![library videoAtPathIsCompatibleWithSavedPhotosAlbum: exportMovieURL]) {
NSLog(@"videoAtPathIsCompatibleWithSavedPhotosAlbum fails for: @",exportMovieURL);
return;
}
[library writeVideoAtPathToSavedPhotosAlbum:exportMovieURL
completionBlock:^(NSURL *assetURL, NSError *error)
{
[self performSelectorOnMainThread:@selector(setTintToNormal)
withObject: NULL
waitUntilDone: YES];
if(error)
{
DLog(@"The video saving failed with the following error =============== %@",error);//notify of completion
}
else
{
DLog(@"The video is saved to the Photos Album successfully");
}
}];
}