2015-06-17 59 views
0

在IOS 9的PhotoFramework中,它們有一個方便的源類型結構。獲取PHAssetSource IOS 8

是否有無法識別IOS 8上的資產源類型?

typedef NS_OPTIONS(NSUInteger, PHAssetSourceType) { 
PHAssetSourceTypeNone   = 0, 
PHAssetSourceTypeUserLibrary  = (1UL << 0), 
PHAssetSourceTypeCloudShared  = (1UL << 1), 
PHAssetSourceTypeiTunesSynced = (1UL << 2), 
} NS_AVAILABLE_IOS(9_0); 

回答

1

查看此代碼。如果您在不使用網絡訪問權限的情況下詢問圖像,則如果圖像位於雲中,則將返回零。

PHFetchOptions* fetchOptions = [[PHFetchOptions alloc] init]; 
      PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options: fetchOptions]; 

      // Get assets from the PHFetchResult object 
      [allPhotosResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) { 
       //NSLog(@"asset %@", asset); 
       PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init]; 
       options.allowNetworkAccess = NO; // <<<< don't allow network access to determine if it's in the cloud or not 
       options.synchronous = YES; // depends on your situation 
       options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; 
[imageManager requestImageDataForAsset: asset options: options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { 

// if imageData is nil then it's not on the device, likely in the cloud, otherwise it's local 

} 
+0

謝謝,這就是我曾經想過要做的事情,它看起來像是確定它的方式。 –