I'd like to a get the name of the Saved Photos album programmatically. The value changes based on locale and whether or not the device has a camera (Camera Roll vs. Saved Photos), so hard-coding is not preferable.
I am aware that I can use AssetsLibrary to get the album name, like so:
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"%#", [group valueForProperty:ALAssetsGroupPropertyName]);
}
failureBlock:^(NSError *error) {}];
However, doing so requires that the user authorize access to Location Services, which is unacceptable for my scenario.
Any other means of gettings this album name without requiring permissions?
You can do that only by using AssestsLibrary, which requires that the users grants access to location services. I suggest you fill a bug report/enhancement request at radar.apple.com.
Cheers,
Hendrik
Related
I have an application that deletes photos from the camera roll. This wipe is initiated remotely. Due to this if a wipe is initiated and the user is not at their phone they it will not wipe because you need to authorize the delete for each image.
Now I've read this is not possible in different questions. However, is it possible to request authorization to the phones photo library just as is done with geolocation when the application finishes loading on the first launch. Would this grant authorization for deleting without the need to confirm for every photo?
This is how I'm currently deleting the photos, it works fine apart from the need to confirm deletion of every image
PHFetchResult *asset = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
[asset enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(#"%#",[obj class]);
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
BOOL req = [obj canPerformEditOperation:PHAssetEditOperationDelete];
if (req) {
NSLog(#"true");
[PHAssetChangeRequest deleteAssets:#[obj]];
}
} completionHandler:^(BOOL success, NSError *error) {
NSLog(#"Finished Delete asset. %#", (success ? #"Success." : error));
if (success) {
NSLog(#"WIPE SUCCESSFUL");
}
}];
}];
It's not possible to delete any photos/videos through the provided APIs without the confirmation alert. There is no way around this.
The app requests authorization for photo to get access permissions to the photos. This permission is to get photos (application can copy all the photos in the device, do you want any app could do so?), not to delete them.
If you want to delete some asset or collections you have to receive specific authorization from the user each time. You can do some changes together with request authorization only once - but you have to contact with the user at least once about this.
I want to save an image (which is downloaded from server) in iOS device photo album and store that image photo album url in local database. My question is, How do i get that photo album image url after saving the image?
I am able to save the image in photo album using the following ALAsset code: But, I need this url image also to be stored in my local db. So next time, i won't download the same image from server and i can load directly from device photo album.
[self.maAssetsLibrary saveImage:image
toAlbum:#"My-Album"
completion:completion
failure:nil];
Please suggest.
UPDATE:
I tried this, but NOT getting me the photo album image URL after saving the image.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
};
[self.maAssetsLibrary saveImage:image toAlbum:#"My-Album" completion:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(#"error");
} else {
NSLog(#"url %#", assetURL);
}
} failure:^(NSError *error) {
}];
});
Due to sandboxing you can't get such a url. As #Lord Zsolt proposes in the comment, you can overcome this by saving images in your application's folder. In this case you might e.g. give them a name that serves as key to identify each image.
EDIT
As #MidhunMP commented, I was wrong on that! There is a way (and I'm happy to know that now) and it comes from this Stack Overflow answer, provided by #CRDave in the comment above.
The main point is to use ALAssetsLibrary's writeImageToSavedPhotosAlbum:orientation:completionBlock: method.
It's always nice to learn.
I'm trying to save a video made in an app to a custom album.
I've tried the solution proposed on Saving Video in an Album Created, however, these blocks are executed asynchronously resulting in my asset in the result block being nil.
I've succeeded in creating the album, writing a video to it doesn't seem to work with the above methods. I have no clue what's going on. Can someone give me a heads up on this?
The url you got is a file url but not an ALAsset url.
You'll need to save that mov to camera roll first and add its asset reference to the custom album.
Check out the example code in this tutorial.
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
for video saving support, just add the function below to the category offered here:
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
-(void)saveVideoLocalUrl:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
//add the asset to the custom photo album
[self writeVideoAtPathToSavedPhotosAlbum:assetURL completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(#"error: %#", [error description]);
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}
I'm trying to use iOS Social.framework to share to Facebook. However, most users will not have Facebook setup in Settings>Facebook so therefore Facebook doesn't show up when you bring up a UIActivityViewController, it just isn't listed. (See UIActivity with no settings for Facebook or just google "facebook doesn't show in UIActivityViewController," there's plenty of people trying to solve this problem.)
Our app already uses the Facebook SDK so I can get at the Facebook account info, so I thought I would just get the info and then save the info in Settings>Facebook. Here's my code. (Which I got from When do we use saveAccount:(ACAccount *)account of ACAccountStore class? and iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert)
- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
//We start creating an account by creating the credentials object
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
//Here we assign credentials and now can save account
newAccount.credential = credential;
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
[VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
[NSArray arrayWithObject:#"basic_info"], (NSString *)ACFacebookPermissionsKey,
ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
nil];
[_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
[self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"the account was saved!");
}
else {
if ([error code] == ACErrorPermissionDenied) {
NSLog(#"Got a ACErrorPermissionDenied, the account was not saved!");
}
NSLog(#"the account was not saved! %d, %#", [error code], error);
}
}];
}
else {
NSLog(#"ERR: %# ",error);
}
}];
}
I added the call to requestAccessToAccountsWithType there because without I was getting a ACErrorPermissionDenied back from saveAccount. When I run this I do see my app slide briefly aside for the Facebook dialog (if I delete my app on Facebook's website it does bring up the full dialog asking me for permissions which I grant.)
The problem is that granted is always NO, so I never get a chance to save the account. What am I missing here?
I am running this on a real device that has the Facebook App installed and setup.
I'd appreciate any help on this, thanks!
There is no solution available for this. iOS native facebook applications are not allowed to write or save account to ACAccountStore. It only allow to access account from the ACAccountStore. iOS only allow to store 1 facebook account at a time. Try to do these steps you will understand this easily,
Add a facebook account to settings App and try to get permission to access it. It will grand permission.
Remove account and try to get the permission it will deny access.
Add a facebook account and get access and try to save new account to ACAccountStore, It will say that Native applications are not allowed to save account to ACAccountStore.
The proposed solution is, Add the account to settings App and login with it and Share using Social framework or presentOSIntegratedDialog.
I want to save a image captured with AVCaptureStillimageOutput and I'm trying to save it using this code :
[self.library writeImageToSavedPhotosAlbum:image metadata:nil completionBlock:nil]:
it's by default saving to PhotoRoll and there is no option to change album.
I found an older guide o how to save image to album using this code:
[self.library saveImage:img toAlbum:albumName withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
but it seems to be deprecated... Is it possible to make it nondeprecated because i think that this method is the one I'm looking for.
All photos go to the SavedPhotos. Once you saved it there you can use the library method
addAssetsGroupAlbumWithName:resultBlock:failureBlock:
and then the ALAssetsGroup method
addAsset:
Please see this answer for more detail:
Create, Delete, and add pictures to albums in the photos app?