ios - 将照片保存到iOS相册,不要全部保存
<p><p>我正在尝试从应用中保存照片,创建相册并将照片保存到其中,但无法正常工作。</p>
<p>有时它会保存一张或另一张照片,但不会保存所有照片。</p>
<p>向大家致以最诚挚的问候和感谢!</p>
<pre><code>for(PFObject *pf in imageFilesArray)
{
PFObject *imageObject = pf;
PFFile *imageFile = ;
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
UIImage *image = ;
orientation:ALAssetOrientationUp completionBlock:^(NSURL *assetURL, NSError *error) {
if(assetURL) {
[self.library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
;
NSLog(@"Adicionado");
} failureBlock:^(NSError *error) {
NSLog(@"%@",error);
}];
}
}];
}
}];
}
;
</code></pre>
<p> - (void) addAsset:(ALAsset*)a toGroup:(NSString*)name inLib:(ALAssetsLibrary*)lib 方法</p>
<pre><code>[lib enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if([ isEqualToString:name]) {
;
*stop = YES;
NSLog(@"added asset to EXISTING group");
}
if(!group) {
[lib addAssetsGroupAlbumWithName:name resultBlock:^(ALAssetsGroup *group) {
;
NSLog(@"added asset to NEW group");
} failureBlock:^(NSError *error) {
NSLog(@"e: %@", error);
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"e: %@", error);
}];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我已经和某人讨论过这个问题 <a href="https://github.com/Kjuly/ALAssetsLibrary-CustomPhotoAlbum/issues/2" rel="noreferrer noopener nofollow">HERE</a> .</p>
<blockquote>
<p>... when there's no photo album available, only part images are saved in a for loop. I tested the code and found that <strong>-addAssetsGroupAlbumWithName:resultBlock:failureBlock:</strong> will process asynchrony, this method will be dispatched several times when the album is not created (this might take some time).</p>
<p>In this case, you can just create a photo album before image adding process.</p>
<pre><code>[self.assetsLibrary addAssetsGroupAlbumWithName:<your_custom_album_name>
resultBlock:nil
failureBlock:nil];
</code></pre>
</blockquote>
<p>随意看看这个库:<a href="https://github.com/Kjuly/ALAssetsLibrary-CustomPhotoAlbum" rel="noreferrer noopener nofollow">ALAssetsLibrary-CustomPhotoAlbum</a> , 它可能对你有很多帮助;)</p></p>
<p style="font-size: 20px;">关于ios - 将照片保存到iOS相册,不要全部保存,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24836069/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24836069/
</a>
</p>
页:
[1]