UI Activity View Errors - ios

I'm quite the beginner to iOS Programming, and I googled how to get the UI Activity View implemented, but I'm getting errors that I do not quite understand. Anyone that can help me figure out what the errors mean in more specific detail and how to fix them, it would be greatly appreciated.
#pragma mark - SHARING OPTIONS (using a DocumentInteractionController) =============
/* =================
NOTE: The following methods work only on real device, not iOS Simulator, and you should have apps like Instagram, iPhoto, etc. already installed into your device!
================= */
-(void)shareImageToAllAppsAvailable {
NSLog(#"This code works only on device. Please test it on iPhone!");
// makes an NSURL file to the processed Image that needs to be saved
NSURL *fileURL;
docIntController.delegate = self;
//Saves the Image to default device directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"My Selfie.jpg"];
UIImage *image = combinedImage;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
//Load the Image Path
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:#"My Selfie.jpg"];
// this blank line here creates error 'use of undeclared identifier 'showActivityViewController''
// Create the URL path to the Image to be saved
fileURL = [[NSURL alloc] initFileURLWithPath:getImagePath];
// Open the Document Interaction controller for Sharing options
-(void)showActivityViewController
{
//-- set up the data objects
NSString *textObject = _aTextView.text;
UIImage *image = [UIImage imageNamed:#"My Selfie.jpg"];
NSArray *activityItems = [NSArray arrayWithObjects:textObject, url, image, nil];
//-- initialising the activity view controller
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
//-- define the activity view completion handler
avc.completionHandler = ^(NSString *activityType, BOOL completed){
NSLog(#"Activity Type selected: %#", activityType);
if (completed) {
NSLog(#"Selected activity was performed.");
} else {
if (activityType == NULL) {
NSLog(#"User dismissed the view controller without making a selection.");
} else {
NSLog(#"Activity was not performed.");
}
}
};
}

You're missing a closing } before your -(void)showActivityViewController declaration.
It looks like you're trying to call that method by defining it within another method, which is not valid Objective-C. Use the self construct to reference methods defined in the same class.
#pragma mark - SHARING OPTIONS (using a DocumentInteractionController) =============
/* =================
NOTE: The following methods work only on real device, not iOS Simulator, and you should have apps like Instagram, iPhoto, etc. already installed into your device!
================= */
-(void)shareImageToAllAppsAvailable {
NSLog(#"This code works only on device. Please test it on iPhone!");
// makes an NSURL file to the processed Image that needs to be saved
NSURL *fileURL;
docIntController.delegate = self;
//Saves the Image to default device directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"My Selfie.jpg"];
UIImage *image = combinedImage;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
//Load the Image Path
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:#"My Selfie.jpg"];
// this blank line here creates error 'use of undeclared identifier 'showActivityViewController''
// Create the URL path to the Image to be saved
fileURL = [[NSURL alloc] initFileURLWithPath:getImagePath];
// Open the Document Interaction controller for Sharing options
[self showActivityViewController]; //added
} //added
-(void)showActivityViewController
{
//-- set up the data objects
NSString *textObject = _aTextView.text;
UIImage *image = [UIImage imageNamed:#"My Selfie.jpg"];
NSArray *activityItems = [NSArray arrayWithObjects:textObject, url, image, nil];
//-- initialising the activity view controller
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
//-- define the activity view completion handler
avc.completionHandler = ^(NSString *activityType, BOOL completed){
NSLog(#"Activity Type selected: %#", activityType);
if (completed) {
NSLog(#"Selected activity was performed.");
} else {
if (activityType == NULL) {
NSLog(#"User dismissed the view controller without making a selection.");
} else {
NSLog(#"Activity was not performed.");
}
}
};
}

Related

How To Move A File Out Of The Inbox Folder When Using Airdrop Between iOS Devices

I am sending database file successfully between iOS devices with the following code:
-(void) doSendDatabase {
UIView *viewTemp = [[UIView alloc] init];
viewTemp.frame = CGRectMake(0.0f, 0.0f, 300, 300);
NSString *currentDatabaseName;
// This is the full path and file name with ext
currentDatabaseName = [self.databases objectAtIndex:[[mainTableView indexPathForSelectedRow] row]];
NSURL *url = [[NSURL alloc] initFileURLWithPath:currentDatabaseName];
UIActivityViewController * airDrop = [[UIActivityViewController alloc]
initWithActivityItems:#[url]
applicationActivities:nil];
airDrop.popoverPresentationController.sourceView = self.view;
[self presentViewController:airDrop
animated:YES
completion:nil];
[url release];
[airDrop release];
[viewTemp release];}
This code works and the database successfully gets sent from the sending iOS device to the receiving device. However, the databases are stored in the Documents/Inbox folder (by design I suppose). I simply want to move the received database files from the Inbox folder up one level into the Documents folder. From what I'm reading I need to handle this in openURL in the App Delegate - but am not sure how to go about this. Any help would be greatly appreciated.
Thank you.
Ok - here's what I did to resolve the problem.
(1) I created a handleInboxItems method in the App Delegate.
-(bool) handleInboxItems {
bool success = YES;
// Get the DBAccess object
DBAccess *dbAccess = [[DBAccess alloc] init];
// Get the Func object
Func *funcObject = [[Func alloc] init];
NSMutableArray *docDatabases;
// get a list of all database files in the Documents/Inbox folder ans store them in the inboxDatabases array
NSMutableArray *inboxDatabases = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *inboxDirectory = [documentsDirectory stringByAppendingPathComponent:#"Inbox"];
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:inboxDirectory];
for (NSString *inboxFileAndPath in directoryEnumerator)
{
//check to see if any of the files in the inbox folder end in the database extension - if so then save it in the inboxDatabases array
if ([[inboxFileAndPath pathExtension] isEqualToString:#“dbext”])
{
[inboxDatabases addObject:[inboxDirectory stringByAppendingPathComponent:inboxFileAndPath]];
}
}
// now go through the inboxDatabases array and copy them from the Documents/Inbox folder to the Documents folder
// loop through all inbox database and see if any of the database names already exist in Documents - if so then we need to tack on a sequential number
for (NSString *inboxDatabaseFileAndPath in inboxDatabases)
{
NSString *inboxDatabaseName = [[inboxDatabaseFileAndPath lastPathComponent] stringByDeletingPathExtension];
// Get the databases array from the DBAccess class (from the Documents folder) - need to get each time since we are moving files in there
docDatabases = [dbAccess getAllDatabases];
// does the inbox database already exist in the documents folder?
NSUInteger arrayIndex = [docDatabases indexOfObject:[funcObject databaseNameToFullPathName:allTrim(inboxDatabaseName)]];
int i = 0;
while (arrayIndex != NSNotFound)
{
++i;
NSString *tempDatabaseName = [NSString stringWithFormat:[inboxDatabaseName stringByAppendingString:#" %d"],i];
// see if the database (with sequential number) already exists
arrayIndex = [docDatabases indexOfObject:[funcObject databaseNameToFullPathName:allTrim(tempDatabaseName)]];
if (arrayIndex == NSNotFound)
{
// it does not exist, we can use this name
inboxDatabaseName = tempDatabaseName;
}
}
// give it full path and extension
NSString *docDatabaseFileAndPathToWrite = [funcObject databaseNameToFullPathName:allTrim(inboxDatabaseName)];
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager copyItemAtPath:inboxDatabaseFileAndPath toPath:docDatabaseFileAndPathToWrite error:&error];
if (success)
{
// delete the inbox database file
success = [fileManager removeItemAtPath:inboxDatabaseFileAndPath error:&error];
if (!success)
{
NSAssert1(0,#"Failed to delete inbox database:'%#'.",[error localizedDescription]);
}
}
else
{
NSAssert1(0,#"Failed to copy inbox database to documents folder:'%#'.",[error localizedDescription]);
}
}
[dbAccess release];
[funcObject release];
[inboxDatabases release];
return success;}
(2) Added a call to this new method in the didFinishLaunchingWithOptions in the App Delegate just in case there is anything stuck in the inbox upon startup.
(3) I added the openURL method to the App Delegate in order to call handleInboxItems. After done, I send a notification so that I can refresh my database list.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
bool success = [self handleInboxItems];
if (success)
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DATABASE_AIRDROPPED object:self];
return success;}
That's it - works as I need it to.

Saving gif file created from screenshots to camera roll

I've got a gif in my documents folder I would like users of the app to be able to access and email to use on other platforms that support gif animation.
I generated the gif file using information from this post...
Create and and export an animated gif via iOS?
The gif file generated and animates correctly (opened directly from simulator's documents folder in safari)
Unfortunately when trying to move the file to the camera roll (for easy email by user) using either UIImageWriteToSavedPhotosAlbum or writeImageDataToSavedPhotosAlbum from ALAssetsLibrary the image seems to be converted to a jpg file and loses all animation.
Checked this by emailing file from camera roll and opening on different platform (the functionality I would like users to have).
I have read every post I could find and from what I've seen it seems possible to save gif files directly from a browser to camera roll and even if they do not animate there they do retain that property when opened in another program so I am hoping what I am trying to do is at least possible : )
Thank for any help, have included my gif creation and failed copying attempts below..
- (void) makeGifFile {
////////////////////
NSDictionary *fileProperties = #{
(__bridge id)kCGImagePropertyGIFDictionary: #{
(__bridge id)kCGImagePropertyGIFLoopCount: #0, // 0 means loop forever
}
};
///////////////////
NSDictionary *frameProperties = #{
(__bridge id)kCGImagePropertyGIFDictionary: #{
(__bridge id)kCGImagePropertyGIFDelayTime: #0.06f, // a float (not double!) in seconds, rounded to centiseconds in the GIF data
}
};
///////////////////////
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSURL *fileURL = [documentsDirectoryURL URLByAppendingPathComponent:#"animated.gif"];
////////////////////////
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeGIF, self.screenshotnumber, NULL);
CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)fileProperties);
/////////////////////////////////
for (NSUInteger i = 1; i < self.screenshotnumber+1; i++) {
#autoreleasepool {
////
NSString *name = [NSString stringWithFormat: #"Screenshot%d", i];
NSString *pathstring = [NSString stringWithFormat: #"Documents/%#.png", name];
NSString *gifPath = [NSHomeDirectory() stringByAppendingPathComponent:pathstring];
/////
UIImage *image = [UIImage imageWithContentsOfFile:gifPath];
CGImageDestinationAddImage(destination, image.CGImage, (__bridge CFDictionaryRef)frameProperties); }
}
///////////////////////////////////////
if (!CGImageDestinationFinalize(destination)) {
NSLog(#"failed to finalize image destination");
}
CFRelease(destination);
NSLog(#"url=%#", fileURL);
//////////////////////////////
///
/// saved in documents directory
/////////////////////////////
//////////////////////////
//////
///// now move to camera roll
///////////////////////
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *gifImagePath = [NSString stringWithFormat:#"%#/%#", documentDirectory, #"animated.gif"];
UIImage *gifImage = [UIImage imageWithContentsOfFile:gifImagePath];
UIImageWriteToSavedPhotosAlbum(gifImage, nil, nil, nil);
CCLOG(#"wrote to camera roll");
//////////////////////// gets saved as JPG not gif
//////// next try...
NSData *data = [NSData dataWithContentsOfFile:gifImagePath]; // Your GIF file path which you might have saved in NSDocumentDir or NSTempDir
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(#"Error Saving GIF to Photo Album: %#", error);
} else {
// TODO: success handling
NSLog(#"GIF Saved to %#", assetURL);
// success(gifImagePath);
}
}];
/////////// also gets saved as jpg
}
My methods for creating screenshots for those interested... I have lost track of the post I found this on... if anyone can provide me with the link I will give due credit here ...
Included to have all relevant functions together in case it helps anyone else :)
-(UIImage*) screenshotWithStartNode:(CCNode*)startNode
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize viewSize = [[CCDirector sharedDirector] viewSize];
CCRenderTexture* rtx =
[CCRenderTexture renderTextureWithWidth:viewSize.width
height:viewSize.height];
[rtx begin];
[startNode visit];
[rtx end];
return [rtx getUIImage];
}
- (void) saveScreenShotWithName: (NSString*) name
{
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *tempimage = [self screenshotWithStartNode:n];
NSString *pathstring = [NSString stringWithFormat: #"Documents/%#.png", name];
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:pathstring];
// Write image to PNG
[UIImagePNGRepresentation(tempimage) writeToFile:savePath atomically:YES];
}
Simple loop creates files and then another deletes files from documents directory after gif creation
Sadly this can't be solved. The reason for this is that Photos app can't (at the present) display animated GIFs and it only displays one frame from the GIF as a static image. That doesn't mean though that the gif wasn't saved properly. I haven't tried your code but everything seems Ok.
There's a way of testing this. In Messages app (for example) GIFs are being played correctly, so if you share the GIF image from Photos app via ActivityController, select Message and then send it to yourself, you should see animated GIF image in Messages app.

Move Photos to other folder ios

How to move photos from one folder to another folder in iphone?
I have fetched all photos from camera roll. Now, i want some of them to move to some specific folder in iphone. Is it possible to do?
Yes you can, sort of. As in you can access the user media library and you can copy them to you apps sandbox environment. Since iOS has no public filesystem you will not be able to copy/move them directly to some directory.
The images in the user media librarycan accessed with the AssetsLibrary.
You can add new groups to the user media library and add picture to this group. But you can not move, delete or replace existing images in the user media library.
You can Move All files to Under Documents folder or Caches Folder.
You Can Create Folder Programatically in iPhone Photos.
Please check the below Link for Reference:
iphone: copy or move file from document directory folder
here is some (untested) code for copying the thumbnail & full size version of a photo called 'name' from the shared camera roll to the documents directory in your app's sandbox:
NSString *newNameThumb = #"newThumbName.png";
NSString *newName = #"newFullsizeName.png";
NSString *name = #"nameOfSharedPhotoToMove.png";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
if([representation.filename isEqualToString:name]){
UIImage *latestPhoto = [UIImage imageWithCGImage:[alAsset thumbnail]];
NSData *imageData = UIImagePNGRepresentation(latestPhoto);
UIImage *latestFullPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
NSData *imageFullData = UIImagePNGRepresentation(latestFullPhoto);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* newThumbPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:newNameThumb];
[imageData writeToFile:newThumbPath atomically:YES];
NSString* newFullPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:newName];
[imageFullData writeToFile:newFullPath atomically:YES];
*stop = YES; *innerStop = YES;
});
}
}
}];
} failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(#"No photos found or permission denied");
}];
Try this:
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
NSURL *oldDir = [NSURL fileURLWithPath:#"/tmp/mynewdir"];
NSURL *newDir = [NSURL fileURLWithPath:#"/tmp/mynewdir2"];
[filemgr moveItemAtURL: oldDir toURL: newDir error: nil];
Hope this helps.. :)

How to upload image either .png or .jpg on ftp server in ios.?

I want to upload or save image to FTP server from my iOS app. but every time I get error that ftp not connected
I use SCRFTPRequest library.
here is my code...
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSData * imageData = UIImagePNGRepresentation(image);
NSFileManager * fileManager = [NSFileManager defaultManager];
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.png",image]];
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
NSLog(#"image saved");
[picker dismissViewControllerAnimated:YES completion:nil];
ftpRequest = [SCRFTPRequest requestWithURL:[NSURL URLWithString:#"ftp://myURL"] toUploadFile:fullPath];
ftpRequest.username = #"DemoUser";
ftpRequest.password = #"DemoUser";
ftpRequest.customUploadFileName = #"inapp";
ftpRequest.delegate = self;
[ftpRequest startAsynchronous];
From White Raccoon,
Just Drag and Drop the WhiteRaccoon.h and WhiteRaccoon.m file and import CFNetwork framework in your project.
- (void) upload
{
//the upload request needs the input data to be NSData
//so we first convert the image to NSData
UIImage * ourImage = [UIImage imageNamed:#"space.jpg"];
NSData * ourImageData = UIImageJPEGRepresentation(ourImage, 100);
//we create the upload request
//we don't autorelease the object so that it will be around when the callback gets called
//this is not a good practice, in real life development you should use a retain property to store a reference to the request
WRRequestUpload * uploadImage = [[WRRequestUpload alloc] init];
uploadImage.delegate = self;
//for anonymous login just leave the username and password nil
uploadImage.hostname = #"xxx.xxx.xxx.xxx";
uploadImage.username = #"myuser";
uploadImage.password = #"mypass";
//we set our data
uploadImage.sentData = ourImageData;
//the path needs to be absolute to the FTP root folder.
//full URL would be ftp://xxx.xxx.xxx.xxx/space.jpg
uploadImage.path = #"/space.jpg";
//we start the request
[uploadImage start];
}
-(void) requestCompleted:(WRRequest *) request{
//called if 'request' is completed successfully
NSLog(#"%# completed!", request);
}
-(void) requestFailed:(WRRequest *) request{
//called after 'request' ends in error
//we can print the error message
NSLog(#"%#", request.error.message);
}
-(BOOL) shouldOverwriteFileWithRequest:(WRRequest *)request {
//if the file (ftp://xxx.xxx.xxx.xxx/space.jpg) is already on the FTP server,the delegate is asked if the file should be overwritten
//'request' is the request that intended to create the file
return YES;
}
Finally i got success to upload image file on ftp server.
To upload image on ftp i used Gold Raccoon external library.with this library you can easily upload image to ftp server.
https://github.com/albertodebortoli/GoldRaccoon

UIActivityViewController & UIDocumentInteractionController not showing options

I am new to UIActivityViewController and perhaps I am missing a basic understanding. What I am trying to do is attached a csv, xml and vcard file to activity controller and show dropbox, google drive etc options. I have downloaded and installed dropbox, google drive etc apps on my iPhone.
Now when I launch UIActivityViewController all I see are default message and email app in my acitivity controller. How can I have other apps show up on their too? Do I need to install each and every apps individual SDKs and somehow incorporate them in my app?
This is what I wold like to see
but this is what I see instead.
Here's the code that I have tried so far
-(IBAction) dropBoxAction
{
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
//CSV
NSMutableString *fileNameStr = [NSMutableString stringWithFormat:#"test_CSV_Backup.csv"];
NSString* csvDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr];
NSData *csvData = [NSData dataWithContentsOfFile:csvDataFileStr];
//EXCEL
NSMutableString *fileNameStr2 = [NSMutableString stringWithFormat:#"test_EXCEL_Backup.xml"];
NSString* excelDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr2];
NSData *excelData = [NSData dataWithContentsOfFile:excelDataFileStr];
//VCARD
NSMutableString *fileNameStr3 = [NSMutableString stringWithFormat:#"test_VCARD_Backup.vcf"];
NSString* vcardDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr3];
NSData *vcardData = [NSData dataWithContentsOfFile:vcardDataFileStr];
//adding them all together
NSMutableArray *sharingItems = [NSMutableArray new];
[sharingItems addObject:csvData];
[sharingItems addObject:excelData];
[sharingItems addObject:vcardData];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = #[activity];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:applicationActivities];
[self presentViewController:activityController animated:YES completion:nil];
}
As #rmaddy said, you should use UIDocumentInteractionController to replace UIActivityViewController, just like this:
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileNameStr]];
[dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
For anyone interested in future, here's the code all in one place. Do rate it up if this helps.
In your *.h file add this
#interface v1BackupComplete : UIViewController <UIDocumentInteractionControllerDelegate>
{
UIDocumentInteractionController *docController;
}
In your *.m file add this
/************************
* Dropbox ACTION
************************/
-(IBAction) dropBoxAction2
{
NSLog(#"dropBoxAction2 ...");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSMutableString *fileNameStr3 = [NSMutableString stringWithFormat:#"test_VCARD_Backup.vcf"];
NSString* vcardDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr3];
NSURL *fileURL = [NSURL fileURLWithPath:vcardDataFileStr];
docController = [self setupControllerWithURL:fileURL
usingDelegate:self];
bool didShow = [docController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
NSLog(#"didShow %d ...", didShow);
if (!didShow)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ERROR"
message:#"Sorry. The appropriate apps are not found on this device."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL
usingDelegate:(id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL:fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}
UIActivityViewController only shows standard built-in activities plus any custom activities you pass as applicationActivities.
For what you are doing, you don't want UIActivityViewController. You want a UIDocumentInteractionController. If you just want to display existing apps that can open the file, use one of the presentOpenInMenuFrom... methods.
But note that is to be used for just a single file, not three.
Passing three files makes no sense in this context.
I have used your code here to open with dropbox and only after I have used presentPreview method (bellow) It was worked for me.
The pdf was shown as preview and then on the preview share button click (top right) the dropbox option ("open in dropbox") did the job. As it works in the mail app in the attachment preview.
[interactionController presentPreviewAnimated:YES];
When i tried to open with presentOpenInMenuFromRect it was crashed on selecting "open in dropbox".

Resources