How to share image, text and link using UIDocumentInteractionController in iPhone sdk - ios

How to share image with text(link) using UIDocumentInteractionController in iPhone sdk.
My Code:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// If you go to the folder below, you will find those pictures
NSLog(#"%#",docDir);
NSLog(#"saving png");
NSString *pngFilePath = [NSString stringWithFormat:#"%#/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation([self screenShotWithScroll])];
[data1 writeToFile:pngFilePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
_documentInteractionController.delegate = self;
_documentInteractionController.UTI = #"Your Msg";
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
Image share is working but text share is not working
Can any one help me.

It doesn't look like you can set message text and send an image with UIDocumentInteractionController: that's for opening/viewing/previewing single documents in other apps.
BTW. The UTI property is for declaring the type of the document (see Uniform Type Identifier Concepts).
But you can set a name for the document which mail will use as the subject:
_documentInteractionController.name = #"Your Subject";
To create a mail use the UIActivityViewController with an NSString message and UIImage image activity items.

Related

WeChat iOS SDK Sharing - missing description despite filling parameter

When I try to send link or picture with description paremeter to WeChatMoments or WeChatSession, description is never shown. Every other parameter is shown correctly, except description. There are no errors either. Here goes my code, notice that description is filled:
WXMediaMessage *message = [WXMediaMessage message];
message.title = #"Perfect Title";
message.description = #"Amazing Graphic";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:thumbnailPath]];
[message setThumbImage:[UIImage imageWithContentsOfFile:path]];
WXImageObject *ext = [WXImageObject object];
NSString* filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:contentPath]];
ext.imageData = [NSData dataWithContentsOfFile:filePath] ;
message.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
req.scene = (true)?WXSceneTimeline:WXSceneSession;
[WXApi sendReq:req];
I've tried code samples from WeChatDeveloper documentation, and even despite of filling description paremeter, it does only show link with title/graphic.
My question is, anybody faced same problem and there is any solution for missing description field?
May problem occur because my app is not yet verified?

Attaching a txt-file in mailcomposer ios 7

When use my following script, then the picture and the logfile would be a attached file. Also some other Text (the default signature) from the email would be attached as index.htm to the email when i open it with Outlook.
The Email is sent out from the iPad with iOS 7.0.6
In the Mail-Application on the Mac, the Files are in the middle of the text, before the signature of the mail-application would be written.
When i attach only the image, then all would be fine. When i attache also the logfile.txt, then its like I have descripted and in the Mail-Application of the mac, all special keys (german like ä, ü) are not decoded as utf8.
Where did I make the mistake?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
currentIOS = [[UIDevice currentDevice] systemVersion];
vNumber = #"V"VersionNumber;
subject = [NSString stringWithFormat:#"%# - Meine aktuelle iPad-Nummer",vNumber];
message = [NSString stringWithFormat:#"<p>Hallo liebes EDV-Team,</p> <p>mein Betriebssystem ist: %#</p><p>Und meine iPad-Nummer lautet: %#</p>", currentIOS, udid];
[controller setToRecipients: [NSArray arrayWithObjects:#"email#webpage.de", nil]];
[controller setSubject:subject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSData *noteData = [NSData dataWithContentsOfFile:txtFilePath];
[controller addAttachmentData:noteData mimeType:#"text/plain" fileName:#"logfile.txt"];
UIImage *roboPic = [UIImage imageNamed:#"world_smilie.png"];
NSData *imageData = UIImagePNGRepresentation(roboPic);
[controller addAttachmentData:imageData mimeType:#"image/png" fileName:#"smile.png"];
[controller setMessageBody:message isHTML:YES];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[self presentViewController:controller animated:YES completion:nil];
}
I changed the code for the textfile:
I change the code like elio.d told me:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSString *txtFileContent = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSData *txtFileData = [txtFileContent dataUsingEncoding:NSUTF8StringEncoding];
[controller addAttachmentData:txtFileData
mimeType:#"text/plain"
fileName:#"logfile.txt"];
The logfile.txt would be attached but the signature from the ipad would be attached to the email in ATT00002.htm and now i got also a empty ATT00001.htm
I have the same problem when i change the type of the email (isHTML:NO)

iOS - attaching a PDF file: PDF ok in simulator folder, but corrupted when attached to email on device

Hopefully the title made sense. Here's my situation.
I have one PDF created in Pages then exported as a PDF. I then create another PDF within the app. I create the PDF file with this code:
- (void)makePDF:(NSString*)fileName :(NSDictionary*)dictResults
{
pageSize = CGSizeMake(612, 792);
_strPDFJustCreated = fileName;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName:dictResults];
}
- (void)generatePdfWithFilePath:(NSString *)thefilePath :(NSDictionary*)dictResults
{
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
BOOL done = NO;
do {
...whole lot of coding goodness
done = YES;
} while (!done);
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}
Both files are attached to the email message with this code:
/**********Attach PDF Files**************/
//get path to pdf file
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* pdfFilePath = [documentsDirectory stringByAppendingPathComponent:strPDFFileName];
//convert pdf file to NSData
NSData* pdfData = [NSData dataWithContentsOfFile:pdfFilePath];
//attach the pdf file
[mailViewController addAttachmentData:pdfData mimeType:#"application/pdf" fileName:strPDFFileName];
//get path to pdf file
NSString* pdf2FilePath = [documentsDirectory stringByAppendingPathComponent:#"OER_MarketingContent.pdf"];
//convert pdf file to NSData
NSData* pdf2Data = [NSData dataWithContentsOfFile:pdf2FilePath];
//attach the pdf file
[mailViewController addAttachmentData:pdf2Data mimeType:#"application/pdf" fileName:#"OER_MarketingContent.pdf"];
[self presentViewController:mailViewController animated:YES completion:NULL];
When I take a peak inside the app folder within the iPhone Simulator folder the pdf files are there, they are recognized by the OS as PDF files and I can open and read them. However, when I get an email message delivered (and don't laugh but we use Lotus Notes), I cannot preview the files I can't an error message saying there is no filter available, when I opt to open it (in Preview) it just hangs.
I use the same code in other apps with no problems. My guess then is that I am doing something different somewhere in my code. I can't see anything obvious so my question would be is there a way to test say NSData for success/failure prior to attaching the file or testing it post attachment but pre email?
Thanks
Don't use UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);. Instead, use: NSData * pdfData = [NSData dataWithContentsOfFile:pdfFileName];.
So, the whole thing should end up looking like:
NSString *fileName = #"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:#"email#email.com"]];
[controller setSubject:#"PDFTEST"];
[controller setMessageBody:#"Your text here" isHTML:NO];
NSData * pdfData = [NSData dataWithContentsOfFile:pdfFileName];
NSString *testFileName = [NSString stringWithFormat:#"PDFNAME"];
[controller addAttachmentData:pdfData mimeType:#"application/pdf" fileName:testFileName];
[self presentModalViewController:controller animated:YES];
This worked for me. Let me know if you have any more questions or if this is unclear. Thanks!

iOS - Can't Display Downloaded Image

I am downloaded images using the below code, but whenever I try to display them nothing shows up. I have tested the downloading of the images to my desktop from the app (in simulator) and all the images are created just fine. So I know they are being saved into the App's Documents directory.
Any ideas on what I am doing wrong?
Download Image Code:
-(void)saveThumbnails:(NSMutableArray *)thumbnails{
for(NSNumber *videoID in thumbnails){
// Get an image from the URL below
NSURL *thumbnailURL = [self generateThumbnailURL:[videoID intValue]];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:thumbnailURL]];
NSLog(#"%f,%f",image.size.width,image.size.height);
// Let's save the file into Document folder.
// You can also change this to your desktop for testing. (e.g. /Users/kiichi/Desktop/)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//Find Application's Document Directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:#"DownloadedThumbnails"];
// NSString *dataPath = #"/Users/macminidemo/Desktop/gt";//DEBUG SAVING IMAGE BY SAVING TO DESKTOP FOLDER
//Check if Sub-directory exists, if not, try to create it
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]){
NSError* error;
if([[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]){
NSLog(#"New Folder Created!");
}
else
{
NSLog(#"[%#] ERROR: attempting to write create new directory", [self class]);
NSAssert( FALSE, #"Failed to create directory maybe out of disk space?");
}
}
NSArray *splitFilename = [[self generateThumbnailFilename:[videoID intValue]] componentsSeparatedByString:#"."];//Break Filename Extension Off (not always PNGs)
NSString *subString = [splitFilename objectAtIndex:0];
NSString *formattedFilename = [NSString stringWithFormat:#"%#~ipad.png",subString];
NSString *localFilePath = [dataPath stringByAppendingPathComponent:formattedFilename];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
[imageData writeToFile:localFilePath atomically:YES];
NSLog(#"Image: %# Saved!",formattedFilename);
}
}
Display Image Code:
if(currentVideo.thumbnail!=(id)[NSNull null] || ![currentVideo.thumbnail isEqualToString:#"missing_image.png"]){
NSArray *splitFilename = [currentVideo.thumbnail componentsSeparatedByString:#"."];//Break Filename Extension Off (not always PNGs)
NSString *subString = [splitFilename objectAtIndex:0];
NSString *formattedFilename = [NSString stringWithFormat:#"%#~ipad.png",subString];
UIImage *thumbnailImage = [UIImage imageNamed:formattedFilename];
NSLog(#"Image Name: %#",formattedFilename);
[videoThumbnail setImage:thumbnailImage];
[buttonVideo addSubview:videoThumbnail];
}else{
UIImage *thumbnailImage = [UIImage imageNamed:#"video-details-thumbnail"];
[videoThumbnail setImage:thumbnailImage];
[buttonVideo addSubview:videoThumbnail];
}
*And there are no issues displaying the buttonVideo or anything like that. I have tested just setting a test image and that one display just fine (i.e. the "else" statement when run individually works just fine using the default thumbnail)
The documentation for imageNamed says that it works with files that are in the app's main bundle. This suggests to me that it's only appropriate for images that are supplied as in-app resources. Try imageWithContentsOfFile: to get at the content of the documents directory.

How to set a path for opening the pdf file stored in iBooks in iPad

I write the code to open the pdf file located
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *pdfFilePath =[documentsDir stringByAppendingPathComponent:#"421_core_animation_essentials.pdf"];
fileURL = [NSURL URLWithString:pdfFilePath];
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
[[self navigationController] pushViewController:previewController animated:YES];
[previewController.navigationItem setRightBarButtonItem:nil];
[previewController release];
It is working while testing in simulator but when testing in iPad device it doesn't work.
please help me.
iOS device file systems are case-sensitive unlike the simulator which isn't.
Therefore check the filename for case sensitivity on:
NSString *pdfFilePath =[documentsDir stringByAppendingPathComponent:#"421_core_animation_essentials.pdf"];

Resources