2016-04-11 5 views
1
- (void)updateFetchRequest { 
    PHFetchOptions *options = [PHFetchOptions new]; 

    switch (self.imagePickerController.mediaType) { 
     case QBImagePickerMediaTypeImages: 
      options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage]; 
      break; 

     case QBImagePickerMediaTypeVideos: 
      options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeVideo]; 
      break; 

     default: 
      break; 
    } 

    self.fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetCollections[0] options:options]; 

    PHContentEditingInputRequestOptions *editoptions = [[PHContentEditingInputRequestOptions alloc] init]; 
    [editoptions setCanHandleAdjustmentData:^BOOL(PHAdjustmentData *adjustmentData) { 
     return [adjustmentData.formatIdentifier isEqualToString:AdjustmentFormatIdentifier] && [adjustmentData.formatVersion isEqualToString:@"1.0"]; 
    }]; 

    NSLog(@"fectarray %@",self.fetchResult); 

    PHImageRequestOptions *option = [PHImageRequestOptions new]; 
    option.networkAccessAllowed = YES; 
    option.synchronous = YES; 
    option.version = PHImageRequestOptionsVersionOriginal; 
    PHAssetCollection *assetCollection = self.assetCollections[0]; 

    __weak __typeof(self) weakSelf = self; // New C99 uses __typeof(..) 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     NSLog(@"Work Dispatched"); 
     PHAsset *asset; 

     SyncAlbumNames = [NSString stringWithFormat:@"%@",assetCollection.localizedTitle]; 

     for (int i=0; i<self.fetchResult.count; i++) { 
      asset = weakSelf.fetchResult[i]; 
      NSLog(@"asset is %@",asset); 

      [asset requestContentEditingInputWithOptions:editoptions 
       completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { 
       NSURL *imageURL = contentEditingInput.fullSizeImageURL; 
       NSLog (@"imageUrl %@",imageURL); 

       // [weakSelf getLocalId:[NSString stringWithFormat:@"%@",imageURL]]; 
       [self performSelectorOnMainThread:@selector(getLocalId:) 
        withObject:[NSString stringWithFormat:@"%@",imageURL] 
        waitUntilDone:YES]; 
       if(uparray.count == 0){ 
        [arrayAssets addObject:asset]; 
        [newArray addObject:asset]; 
        if(arrayAssets.count !=0){ 
         [dict setValue:[NSArray arrayWithArray:arrayAssets] 
          forKey:assetCollection.localizedTitle]; 
         NSLog(@"dict count is %lu",(unsigned long)dict.count); 
        } 
        [SyncAlbum getArraySubTypes]; 
        NSLog(@"arrayAssets count %d",arrayAssets.count); 
        NSLog(@"fetchresult count %d",weakSelf.fetchResult.count); 
        __typeof(weakSelf) strongSelf = weakSelf; 
        if (strongSelf) { 
         if(arrayAssets.count + 2 + alcount == strongSelf.fetchResult.count){ 
          [strongSelf SyncAlbums]; 
         } 
         // When finished call back on the main thread: 
         dispatch_async(dispatch_get_main_queue(), ^{ 
          // Return data and update on the main thread 
          // Task 3: Deliver the data to a 3rd party component (always do this on the main thread, especially UI). 
         }); 
        } 
        //add count to array asset 
       }else{ 
        NSLog(@"asset already uploaded"); 
        alcount++; 
        //asset already upload count here.. 
       } 
      }]; 
     } 
    }); 
} 

このメソッドを実行すると、UIがブロックされます。私はSQLiteデータベースを使用しています。誰もこれで私を助けることができますか?iOSの写真フレームワークを使用して画像パスを取得中にUIがブロックされる

+1

updateFetchRequestの呼び出し元はどこですか? – BigOmega

答えて

1

私はあなたCMD +は

option.synchronous = YES; 

同期のショーをクリックしてくださいHighQualityFormat

// return only a single result, blocking until available (or failure). Defaults to NO 

また設定

PHImageRequestOptionsDeliveryMode 

が真=同期強制することならばと考えています。

+0

ねえ。私はそれを非同期にしようとしましたが、それと同じ問題が続いています。 –

+0

問題が解決しました。助けてくれてありがとう。メソッド[asset requestContentEditingInputWithOptions:editoptions completionHandler:^(PHContentEditingInput * contentEditingInput、NSDictionary * info){ NSURL * imageURL = contentEditingInput.fullSizeImageURL; }]; UIをブロックしていました。私は方法を変更し、それは働いた。ありがとう。 –

関連する問題