dispatch_get_main_queue不起作用

时间:2014-11-28 19:49:47

标签: ios ios8.1 base-sdk

我的iOS基础SDK是8.1。我在8.1模拟器上运行时dispatch_get_main_queue正常工作。但是,当我在7.1模拟器上运行它时,它不会被调用。我注意到dispatch_get_main_queue已在iOS 8.0及更高版本中重新实现。

我该如何解决这个问题?改变基础SDK还是什么?

我的代码

    AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];

    // audio track
    AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
                                                                        preferredTrackID:kCMPersistentTrackID_Invalid];
    //
    NSError *error;

    AVAsset *videoAsset = [AVAsset assetWithURL:videoURL];
    [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
                        ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] firstObject]
                         atTime:kCMTimeZero
                          error:&error];
    if (error) {
        NSLog(@"extract audio error!");
        return;
    }
    error = nil;

    // audio path
    NSString *path = [NSString stringWithFormat:@"%@newAudio.m4a", NSTemporaryDirectory()];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) {
            NSLog(@"audio cannot be saved!");
        }
    }
    // exporter
    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
                                                                      presetName:AVAssetExportPresetAppleM4A];
    exporter.outputURL = [NSURL fileURLWithPath:path];
    exporter.outputFileType = AVFileTypeAppleM4A;
    exporter.shouldOptimizeForNetworkUse = YES;
    [exporter exportAsynchronouslyWithCompletionHandler:^{
        //NSLog(@"export status: %ld", exporter.status);
        dispatch_async(dispatch_get_main_queue(), ^{
            [self exportDidFinish:exporter];
        });
    }];
}

1 个答案:

答案 0 :(得分:0)

最后我想通了。 presetName需要是AVAssetExportPresetPassthrough才能在iOS 7模拟器上正常工作。我不知道为什么,但谢谢@Kai和@Rob的回复。