Dsiable Authorization request when deleting PHAsset - ios

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.

Related

Saving image in iOS photo album(my folder) and have the image url stored

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.

Facebook iOS SDK - Post Custom Story

I'm trying to do something that seems to be an order of magnitude more difficult than necessary.
I've got an iOS app that is written against a Parse backend. Our app's users can create items to store and they can sometimes generate alerts for these items.
I want to post a simple alert for a user to Facebook.
I've read quite a bit on the Facebook website about integrating Facebook into iOS, but their documentation is confusing and I've seen more than one person on StackOverflow mention that their iOS code is at least sometimes flawed.
Basically, the custom story will include the following items:
Story Title
Story Description (usually not very much text in here)
One or more pictures (I'd settle for 1, but I'd love to be able to post multiples)
If possible, a user-supplied GPS location.
I will admit up front that I'm a developer who is learning Facebook for work purposes, and I am far from being an expert on Facebook.
When I play around in the Facebook app, I can add a status update that can include:
Text
Picture(s)
Friends
What I'm doing
Where I am (or some location)
However, in the Facebook SDK, there appears to be only the following 2 options for posting a status update:
startForPostStatusUpdate:completionHandler:
startForPostStatusUpdate:place:tags:completionHandler:
If I'm missing something there, please let me know.
Secondly, I'm trying to follow Facebook's documentation and sample code to do the following sequence of events:
Upload and stage an image resource
Create an object (in my app, I've registered an "alert" object)
Create an action (in my app, I've registered a "post" action)
Here's the code that I've pieced together from Facebook's website (comments are mostly from other people's code, not my own):
- (void)postToFacebookWithAlert:(PFObject *)alert image:(UIImage *)image {
// Stage the image
[FBRequestConnection startForUploadStagingResourceWithImage:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// See: https://developers.facebook.com/docs/ios/errors
} else {
// Package image inside a dictionary, inside an array like we'll need it for the object
NSArray *image = #[#{#"url": [result objectForKey:#"uri"], #"user_generated" : #"true" }];
// Create an object
NSString *caption = // user-generate content
NSMutableDictionary<FBOpenGraphObject> *alert;
alert = [FBGraphObject openGraphObjectForPostWithType:#"<myapp>:alert"
title:caption
image:image
url:nil
description:alert[#"subtitle"]];
alert.provisionedForPost = YES;
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:alert completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// An error occurred
} else {
NSMutableDictionary<FBGraphObject> *post = [FBGraphObject graphObject];
post[#"alert"] = result[#"id"];
[FBRequestConnection startForPostWithGraphPath:#"me/<myapp>:post" graphObject:post completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"startForPostWithGraphPath:graphObject:completionHandler:");
if (error != nil) {
// An error occurred
NSLog(#"Encountered an error posting to Open Graph: %#", error);
} else {
NSLog(#"OG story posted, story id: %#", result[#"id"]);
}
}];
}
}];
}
}];
}
I've actually gotten this code to work one time. I'm logged in as my own personal Facebook account. If I go to my activity log, I can see the items that I'm trying to post. If I go to my photos, I can see the photos that I'm trying to upload. If I view my profile from my wife's app/account, it doesn't show up.
Does anyone have working code that does what I want?
Maybe you need to set "fb:explicitly_shared" to "true" and it should be reviewed by Facebook.
After your review pass, you can add the option like below.
[post setObject:#"true" forKey:#"fb:explicitly_shared"];

Prevent app from using Facebook single sign on?

I have taken over an app that uses Facebook as a login. I want to force the user to be taken to a UIWebView via a URL. Also when a user signs into our app with some other account, say twitter, but then wants to share via Facebook, I want the user to be taken to Facebook login via UIWebView URL not via single sign on.
The apps works as I want it (see above) if the person has not setup single sign on via iPhone > Setting > Facebook. But if the user has setup Single Sign On via iPHone > Settings > Facebook then the app breaks. We are getting an error that the app needs to be officially put in the Facebook app process here https://developers.facebook.com/apps.
We don't want to jump through Facebooks hoops (images, bundle id's etc,...) so we would rather force the user to login via the Facebook webpage via a webview url.
Can I prevent my app from trying to use the Single Sign On on the iphone?
This did it.
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
// call the legacy session delegate
//Now the session is open do corresponding UI changes
self.facebookButton.selected = YES;
self.shareButton.enabled = YES;
self.shareUIButton.enabled = self.shareButton.enabled;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kShouldPostToFacebookKey];
break;
case FBSessionStateClosedLoginFailed:
{ // prefer to keep decls near to their use
// unpack the error code and reason in order to compute cancel bool
NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
BOOL userDidCancel = !errorCode && (!errorReason ||
[errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);
// call the legacy session delegate if needed
//[[delegate facebook] fbDialogNotLogin:userDidCancel];
}
break;
default:
break; // so we do nothing in response to those state transitions
}
}];

How to save video to custom album?

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];
}];
}

Saved Photos album name without Location Services permission

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

Resources