Download image from iCloud Drive iOS objective C - ios

I have gone through many links, but nothing worked for me. All i need to do is fetch all iCloud Drive files and download images. I succeeded fetching all files using below code
- (void)presentDocumentPicker {
NSArray *documentTypes = #[#"public.content", #"public.text", #"public.source-code ", #"public.image", #"public.audiovisual-content", #"com.adobe.pdf", #"com.apple.keynote.key", #"com.microsoft.word.doc", #"com.microsoft.excel.xls", #"com.microsoft.powerpoint.ppt"];
UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
documentPickerViewController.delegate = self;
[self presentViewController:documentPickerViewController animated:YES completion:nil];
}
#pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
self.documentURL = url;
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.delegate = self;
previewController.dataSource = self;
[self.navigationController pushViewController:previewController animated:YES];
}
now i don't know how to proceed further to download image.

i was able to download images using this
#pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
self.documentURL = url;
NSNumber *isDownloadedValue = NULL;
BOOL success = [url getResourceValue:&isDownloadedValue forKey: NSURLUbiquitousItemIsDownloadingKey error:NULL];
if (success && ![isDownloadedValue boolValue]) {
[[NSFileManager defaultManager]startDownloadingUbiquitousItemAtURL:url error:nil];
// load image from Ubiquity Documents directory
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage * image = [UIImage imageWithData:imageData];
}
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.delegate = self;
previewController.dataSource = self;
[self.navigationController pushViewController:previewController animated:YES];
}

Related

Xcode 8: [Generic] Creating an image format with an unknown type is an error Objective C

I am getting the above error when using uiimagepicker controller. Here is my code:
- (BOOL) startCameraControllerFromViewController:(UIViewController *)controller andisImageFromCamera:(BOOL)isCameraCapture {
if(self.picker == nil) {
/**< instansiate UIImagePickerController object */
self.picker = [[UIImagePickerController alloc] init];;
}
/**< Check isSourceTypeAvailable for possible sources (camera and photolibrary) */
if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO))
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Oops!! This feature is not supported on your device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
return NO;
}
self.picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.picker.delegate = self;
self.picker.mediaTypes =[NSArray arrayWithObjects: (NSString *) kUTTypeMovie, (NSString *) kUTTypeImage, nil];
self.picker.videoMaximumDuration = MAX_VIDEO_DURATION;
self.picker.allowsEditing = YES;
self.picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
/**< if editing is required*/
[self presentViewController:self.picker animated:YES completion:^{
}];
return YES;
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *videoURL = [info valueForKey:UIImagePickerControllerMediaURL];
NSString *pathToVideo = [videoURL path];
if(![pathToVideo isEqualToString:#""] && pathToVideo != nil) {
BOOL okToSaveVideo = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(pathToVideo);
if (okToSaveVideo) {
//UISaveVideoAtPathToSavedPhotosAlbum(pathToVideo, self, #selector(video:didFinishSavingWithError:contextInfo:), NULL);
}
}
if ([info[UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]) {
// video
isVideoFromGallery = YES;
isMediaTypeVideo = YES;
[self videoCaptureSaveAction:videoURL andMediaInfo:info];
}
else{
isMediaTypeVideo = NO;
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.previewImage = chosenImage;
self.capturedImageData = UIImageJPEGRepresentation(chosenImage, 90);
[self performSegueWithIdentifier:#"previewCapture" sender:self];
}
}
Picking the video is working. But when i am selecting the image i am gettin the error: [Generic] Creating an image format with an unknown type is an error. I have read other posts about this error, changed the delegate method, but still its not working. Please help.

Keyword Search in iOS

I am new to iOS. I have a UITextfield and a Keyword Search Button. When ever I want to search a keyword from a service and press enter. Tt should display the related searched keyword from a service. Please help me to fix this issue? TIA!
- (IBAction)KeywordSearchClicked:(id)sender {
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[self KeywordcallSignupProfileService:dict];
}
-(void)KeywordcallSignupProfileService:(NSMutableDictionary *)dict
{
[SVProgressHUD showWithStatus:#"" maskType:SVProgressHUDMaskTypeBlack]; // Progress
NSString * post = [[NSString alloc]initWithFormat:#"userId=%#&key_word%#",UserId,[dict objectForKey:#"key_word"]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.amarbiyashaadi.com/service/amarbiya-service.svc/userKeywordSearch/"]];
RBConnect = [[RBConnection alloc]init];
RBConnect.delegate = self;
[RBConnect postRequestForUrl:url postBody:post];
}
#pragma mark - MRConnection Delegate Methods
- (void)jsonData:(NSDictionary *)jsonDict
{
[SVProgressHUD dismiss];
NSMutableArray *jsonArr;
NSMutableDictionary *userDict,*dict;
NSArray *arr=[jsonDict allKeys];
jsonArr=[jsonDict objectForKey:#"DataTable"];
if (jsonArr.count>0) {
// Save credentials in user defaults
matchesProfileArr=[jsonArr mutableCopy];
DisplayTableViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"DisplayTableViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
else
{
NSString *error=#"Somthing Went Wrong";
[SVProgressHUD showErrorWithStatus:error];
}
}

iOS 9 UIDocumentInteractionController does not open file with the app

In previous iOS, I used this code and UIDocumentInteractionController to open a file, from my app, with another app. Since iOS 9, the UIDocumentInteractionController appears on the screen, I select the option "Copy to", but nothing happens. How can I solve this?
NSURL *URL = [NSURL fileURLWithPath:path];
if (URL != nil) {
// Initialize Document Interaction Controller
documentController = [UIDocumentInteractionController interactionControllerWithURL:URL];
documentController.delegate = self;
[documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
you have to manage your response time of open :-
-(void)exportToDropBox{
[self performSelector:#selector(presentImagePicker) withObject:nil afterDelay:1.0];
}
-(void)presentImagePicker{
NSURL *targetURL = [NSURL fileURLWithPath:exportedPdfFileName];
[self presentDocumentWithURL2:targetURL];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
return self;
}
- (void)presentDocumentWithURL2:(NSURL*)url {
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.documentController.delegate = self;
[self.documentController presentOpenInMenuFromRect:CGRectMake(self.view.frame.size.width/2 - 49/2, self.view.frame.size.height-49, 49, 49) inView:self.view animated:YES];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
self.documentController = nil;
}

FBSDKShareDialog delegate not called

I use the latest Facebook SDK for iOS platform.I use FBSDKShareDialog to share image to Facebook,the code can share image to Facebook.But I want to get the share result delegate.
- (void)sharedImage:(UIImage *) sharedImage
fromViewController:(UIViewController *) fromViewController {
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = sharedImage;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = fromViewController;
dialog.shareContent = content;
dialog.delegate = self;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
Also I add suggest code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
[[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
But the FBSDKSharingDelegate method has been never called.
You are setting fromViewController properly but that controller should be the delegate not the object.Below is code that is working and delegate is getting called
- (IBAction)facebookButtonClick:(UIButton *)sender {
// FacebookShare *facebookShare = [[FacebookShare alloc] init];
// [facebookShare sharedImage:[UIImage imageNamed:#"facebook_share"]
// fromViewController:self];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:#"facebook_share"];
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
//FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
NSLog(#"completed");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(#"fail %#",error.description);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(#"cancel");
}
In my case ,that 's because my view controller has dismiss , so that's impossible to call my delegate function. So please check weather your view controller was dismissed . Hope would help .

Video saving and display in the iOS app.

I'm developing an app where user can record video and save it in the library/or custom album. I'm able to create the custom album and record the video and save it in the default photo library i.e., camera roll.. But i'm unable to save it to the custom album. and other thing is the saved videos in the album must be showed in the collection view of the app i.e., like the gallery view.. so that user can able to click on the videos for the play.. it might be in the grid view/ collection view or might be in the table view where the UIImage should should display the videos saved in the album..
Here's code section which i used in the app development for creating the custom album.
ALAssetsLibrary* libraryFolder = [[ALAssetsLibrary alloc] init];
[libraryFolder addAssetsGroupAlbumWithName:#"HEP" resultBlock:^(ALAssetsGroup *group)
{
NSLog(#"Adding Folder:'My Album', success: %s", group.editable ? "Success" : "Already created: Not Success");
} failureBlock:^(NSError *error)
{
NSLog(#"Error: Adding on Folder");
}];
For recording the video in the app.
- (IBAction)StartRecord:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
}
For saving it in the album i.e., default photo album not the custom album i created.
-(BOOL)startMediaBrowserFromViewController:(UIViewController*)controller usingDelegate:(id )delegate {
// 1 - Validations
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil)) {
return NO;
}
// 2 - Get image picker
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
mediaUI.allowsEditing = YES;
mediaUI.delegate = delegate;
// 3 - Display image picker
[controller presentModalViewController:mediaUI animated:YES];
return YES;
}
Since i'm beginner in iOS still learning.. I'm searching since for a month now. So please help me.
First create your album folder with below code & make sure this code paste in AppDelegate.m file didFinishLaunchingWithOptions method :
ALAssetsLibrary* libraryFolderSozialConnectVideo = [[ALAssetsLibrary alloc] init];
[libraryFolderSozialConnectVideo addAssetsGroupAlbumWithName:#"HEP" resultBlock:^(ALAssetsGroup *group)
{
NSLog(#"HEP Folder Created");
} failureBlock:^(NSError *error) {
NSLog(#"Error: Adding on Folder");
}];
Now, use below function for download your video in HEP folder :
- (void)downloadVideo:(NSURL *)videoURL {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(#"Downloading Started");
NSData *urlData = [NSData dataWithContentsOfURL:videoURL];
if (urlData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"thefile.mp4"];
[urlData writeToFile:filePath atomically:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[self.library saveVideo:[NSURL fileURLWithPath:filePath] toAlbum:#"HEP" completion:^(NSURL *assetURL, NSError *error)
{
NSLog(#"Success downloaded");
} failure:^(NSError *error) {
NSLog(#"Error : %#", [error localizedDescription]);
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[self.navigationController popViewControllerAnimated:YES];
}];
});
}
}); }
for videoURL in your didFinishPickingMediaWithInfo method call above function with below code :
self.library = [[ALAssetsLibrary alloc] init];
[self downloadVideo:[info valueForKey:UIImagePickerControllerMediaURL]];
I hope this works . . .

Resources