我正在構建一個帶屏幕截圖按鈕的應用程序。現在我想要將此應用中製作的所有屏幕截圖保存在同一個自定義名稱應用專輯中。我已經知道如何在應用程序第一次打開代碼時創建相冊。總是將截圖保存在「照片」中相同的自定義名稱應用程序相冊中
-(void)createAppAlbum
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollectionChangeRequest *changeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"App Album Name"];
albumPlaceholder = changeRequest.placeholderForCreatedAssetCollection;
}
completionHandler:^(BOOL success, NSError *error) {
if (success) {
fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[albumPlaceholder.localIdentifier] options:nil];
assetCollection = fetchResult.firstObject;
}
else {
NSLog(@"Error creating album: %@", error);}
}];
}
所以我的應用程序創建一個名爲「應用程序專輯名稱」專輯: 我與像照片框架創建我的專輯。 我能夠把我的截圖保存在我的新專輯按鈕,如:
-(IBAction)screenshot:(id)sender
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
[assetCollectionChangeRequest addAssets:@[[assetChangeRequest placeholderForCreatedAsset]]];
} completionHandler:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"Error creating asset: %@", error);
}
}];
}
如果我離開這個的viewController,並取回後,我想找到的專輯,我已經創建,並保存在同一張專輯中的另一個屏幕截圖,因爲我不想每次進入此視圖控制器時都創建一個。
所以我的問題是,我將如何得到這張專輯我的名字創建了第一次,然後在保存新的屏幕截圖
的[iOS版保存在一個應用程序特定相冊照片](可能的複製http://stackoverflow.com/questions/11972185/ios-save-photo-in-an-app-specific-album) – Fennelouski
@Fennelouski - iOS 5,也沒有使用Photo框架。 – MOzeb
你能解釋一下難題嗎?當你創建相冊時,你會得到它的標識符。從此,通過其標識符訪問相冊。你有什麼困難? – matt