由于 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");
}
}];
}