UIDocumentInteractionController Does Not Show Mail Option - ios

Heres the UIDocuemtnInteractionController from my application(does not show mail option)
Here the one that Apples sample project uses
Here are the respective codes
My application
docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[docInteractionController presentOpenInMenuFromBarButtonItem:(UIBarButtonItem*)sender animated:YES];
Apple Sample Project
NSURL *fileURL;
if (cellIndexPath.section == 0)
{
// for section 0, we preview the docs built into our app
fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:documents[cellIndexPath.row] ofType:nil]];
}
else
{
// for secton 1, we preview the docs found in the Documents folder
fileURL = [self.documentURLs objectAtIndex:cellIndexPath.row];
}
self.docInteractionController.URL = fileURL;
[self.docInteractionController presentOptionsMenuFromRect:longPressGesture.view.frame
inView:longPressGesture.view
animated:YES];
WHAT SHOULD I DO TO GET THE MAIL OPTION?

To provide the Mail option, -presentOpenInMenuFromBarButtonItem: needs to be -presentOptionsMenuFromRect:
As per the Apple Docs on UIDocumentInteractionController
For -presentOpenInMenuFromBarButtonItem:animated: it says:
This method is similar to the
presentOptionsMenuFromBarButtonItem:animated: method, but presents a
menu restricted to a list of apps capable of opening the current
document. This determination is made based on the document type (as
indicated by the UTI property) and on the document types supported by
the installed apps.
...
If there are no registered apps that support opening the document, the
document interaction controller does not display a menu.
So:
To present options to open the file, use -presentOpenInMenuFromBarButtonItem:
To present all possible options applicable on the file, use -presentOptionsMenuFromBarButtonItem: or the generic -presentOptionsMenuFromRect:
Also... for any file, it would be better to specify the UTI type:
Example:
docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
//[docInteractionController setDelegate:self];
[docInteractionController setUTI:#"public.data"];
[docInteractionController presentOptionsMenuFromBarButtonItem:(UIBarButtonItem*)sender
animated:YES];
//or a generic method
//[docInteractionController presentOptionsMenuFromRect:sender.frame
// animated:YES];

Related

PDF in UIWebView not showing digital signature

I am having a PDF file containing digital signature and other data but when I display the PDF in UIWebView digital signature is not visible, although other data is visible. If anybody know how make it visible please let me know.Thank you
why you are using in webview. if you want to preview the PDF use UIDocumentInteractionController, it is easy to use, do like
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"sample" withExtension:#"pdf"];
if (URL) {
// Initialize Document Interaction Controller
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
// Configure Document Interaction Controller
[self.documentInteractionController setDelegate:self];
// Preview PDF
[self.documentInteractionController presentPreviewAnimated:YES];
}
for sample tutorial
because apple does not fully support PDF digital signature. If you want to show pdf signature on iPhone,you should import a third pdf library such as mupdf,PSPDFKit.

Is it possible to view a PDF file from an URL link using Quick Look Framework

As the title says, I need to display a PDF file stored in a remote server without downloading it on the device just by using an URL link. Is it possible to do it by using the Quick Look framework?
I am using this code below:
- (void)openDocument {
QLPreviewController *docPreviewController = [[QLPreviewController alloc] init];
[docPreviewController setDataSource:self];
[docPreviewController setDelegate:self];
[docPreviewController setCurrentPreviewItemIndex:sender.tag];
[self.destinationViewController presentViewController:docPreviewController animated:true completion:nil];
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return [NSURL fileURLWithPath:#"http://www.domain.com/file.pdf"];
}
But I have this problem in the console:
UIDocumentInteractionController: invalid scheme https. Only the file scheme is supported.
No it's not supported by current QLFramework.
All quicklook supported items should conforms to "QLPreviewItem" protocol.
According to QL's document
The methods in the QLPreviewItem protocol are also declared as a category on the NSURL class. As a result, you can use NSURL objects directly as preview items—provided that you want to use the default titles of those items.
QLPreviewItem protocol contains previewItemURL attribute, which is a URL type. But the document tells us directly:
The value of this property must be a file-type URL.
In other words, it doesn't accept other url schema.
I have resolved by using UIDocumentInteractionController
UIDocumentInteractionController *viewer = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
viewer.delegate = self;
[viewer presentPreviewAnimated:YES];

Share image through WhatsApp, just show WhatsApp icon

I use this piece of code, but it shows other apps.
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"ABC" withExtension:#"png"];
if (URL)
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
[self.documentInteractionController setDelegate:self];
CGRect rect = self.view.frame;
[self.documentInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
How can I show the WhatsApp icon only?
Here are the WhatsApp developer docs: https://www.whatsapp.com/faq/iphone/23559013
Here is the relevant bit:
Alternatively, if you want to show only WhatsApp in the application
list (instead of WhatsApp plus any other public/*-conforming apps) you
can specify a file of one of aforementioned types saved with the
extension that is exclusive to WhatsApp:
images - «.wai» which is of type net.whatsapp.image
videos - «.wam» which is of type net.whatsapp.movie
audio files - «.waa» which is of type net.whatsapp.audio
So in order to share an image you would set the UTI of your UIDocumentInteractionController to net.whatsapp.image and append the extension .wai to your filepath.
Additionally, this question may have some helpful example code.

Interact with Mail though UIDocumentInteractionController

I'm sharing a PDF to other apps through the UIDocumentInteractionController. Prior to adding this functionality, I had a custom 'send to email' button using the MFMailComposeViewController - yet now there's also a Mail button in my UIDocumentInteractionController, which I'd like to make use of, to avoid having duplicate buttons.
My issue is, through the old mail controller, I used to set a subject, and content text, whereas if I use the UIDocumentInteractionController - I only get a blank email with the PDF attachment. Does anyone know a way I could work round this and get my custom subject and content when using the UIDocumentInteractionController?
I couldn't find anything obvious in the documentation, and clearly I can't meddle with the Mail app to make it communicate with my app - but wondered if anyone else had encountered the problem, and sussed out a 'back-door' solution.
Below is the code for how I'm currently creating and initalising my UIDocumentInteractionController:
-(void)openDocumentIn:(NSString*)filepath
{
//NSString * filePath = [[NSBundle mainBundle]
pathForResource:filePath ofType:#"pdf"];
documentController = [UIDocumentInteractionController
interactionControllerWithURL:[NSURL fileURLWithPath:filepath]];
documentController.delegate = self;
documentController.UTI = #"com.adobe.pdf";
[documentController presentOptionsMenuFromBarButtonItem:
[self.imageViewController exportQuote] animated:YES];
}
You can do this through the following code
[self.documentInteractionController setName:#"My Email Subject"];

Which file types can UIDocumentInteractionController preview?

I'm putting a UIDocumentInteractionController into my app, which can download arbitrary file types from a server.
It's there for two purposes:
To allow the user to 'Open In' the file in another app that may be able to view the file.
To preview files that the built-in UIDocumentInteractionController is able to preview.
What I'd like to so is to only attempt to display the preview for file types that the system is able to preview. For example, if it's a zip file, the system can't preview that so I want to go straight to the 'Open In'.
I can't find anywhere a list of the types that are supported for preview.
Here's my code:
self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
[self.docController setDelegate:self];
// I'd like to skip this line if the system can't preview the file.
BOOL isOpen = [self.docController presentPreviewAnimated:YES];
if (!isOpen) {
BOOL canOpen = [self.docController presentOpenInMenuFromRect:CGRectMake(300, 300, 100, 100)
inView:self.view
animated:NO];
if (!canOpen) {
// tell user to install an app that's able to open this file.
return;
}
}
The method presentPreviewAnimated: returns a BOOL value (YES if it manages to preview and NO for not managing) so you can:
if (![self.docController presentPreviewAnimated:YES])
{
//present openIn
}

Resources