UIDocumentInteractionController Disable Options Menu - ios

I have a PDF showing in a UIDocumentInteractionController and its great.
Problem is, the point of the app is to protect the PDF from being shared etc. Hence I want to get rid of the options button that appears.
There are 1000 similar Q's on stack, but before you go linking me to what I have already read please keep in mind that I need an iOS6 solution.
I have tried implementing the willShowMenu related functions, and a bunch of other stuff.
End of the day, this needs to get onto the store, and we all know how rigid apple are, so if anyone has a solid store-aproved ios6 solution that would be great.
If not, could anyone point me in the right direction and I will work it out. Is there an alternative to UIDocumentInteractionController for display (but copy protecting) PDFs?
Thanks.

You can use UIWebView to display PDF file.
To disable copy menu, Add the following code in the webViewDidFinishLoad delegate of UIWebView
[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.style.webkitUserSelect='none';"];
[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.style.webkitTouchCallout='none';"]

Related

Tabbed iOS WebKit Browser with Swift

In short I am trying to build some typical browser functionalities in a Swift iOS app with WKWebViews (WebKit). I already have a functioning browser based on a WKWebView, which already has a menu bar with a URL input, navigation buttons, a share button, page title etc.
What I am struggling with is creating tabs for the browser. At first this seemed trivial as surely WKWebViews would support this in some way. Well, as far as I can tell they do not (looked at and tried multiple tutorials incl. hackingwithswift, Ray Wenderlich etc. + I checked Apple's documentation + stackoverflow)
This is what I have come up with so far:
1) Creating a new tab/opening a new URL should create a new UIView + WKWebView programmatically (I'll have to make a subclass out of my current browser view)
=> this should create a separate thread for each WKWebView/tab according to Apple's documentation
2) I need something like a Collection View (or Stack Views etc.) to store screenshot images of the already open tabs as a preview page of all tabs. The cells should be linked via a delegate to the corresponding WkWebView and they should have a close button to close (= delete) the tabs.
Am I overthinking this? If I go down this path I have to find a way to wire up (and subsequently delete) multiple delegates and views to the Collection View dynamically and I have to store & delete screenshots every time the user interacts with the tabs. It seems VERY messy. But given that Chrome on iOS is based on WebKit as of late, it's obviously doable.
How would you tackle this problem?
PS I didn't include a mockup because you all know how the tabs in Chrome, Safari etc. on iOS look like.
EDIT:
I am just looking for a clean and sensible way to add/remove and show the multiple WKWebViews, which are created by opening new tabs - just like in Chrome for iOS or Safari etc.
Ok, I have solved this today :) I will have a main UIView and then multiple WKWebViews, which can be "zoomed in" in order to enter full screen mode. No need for screenshots etc.

URL Visible in UIActivityViewController

I've seen this used in some apps and I can't seem to figure out how it's done - there seems to be nothing to set. When I set the url to share, it doesn't pop up automatically either, and I can't find any reference to it anywhere on the Internet which makes me feel like an idiot. Any possibilities? It's not urgent anyway I'm just curious. Thanks.
Screenshot of iOS Device with the UIActivityViewController visible with the URL bar:
http://twitter.com/SunburstEnzo/status/617736706402484224/photo/1
Edit: I can't believe I need 10 reputation to show you my problem.
There's no built-in way to do this. However, there's a third-party component named JDSActivityVC which enables you to achieve this effect.
It's just a subclass of UIActivityViewController that adds a custom UIView with an UILabel.

iOS Share Extension Doesn't Terminate

I've created an iOS share extension with a custom UI (not using SLComposeServiceViewController) and everything works great.
Once the extension is invoked, it takes a shared URL or text and sends it. That's all it does and it works well.
The custom UI is simple. One image view that shows a graphic indicating that it is sending and then that changes to say "Sent" once done. Then this fades out.
What is going wrong is after this is done, the extension seems to disappear, but I can't control the host application anymore. It's as if an invisible window or view is on top of everything. (For example, an image rotator in Safari still rotates, but I can't scroll or tap links or buttons, etc.)
I'm calling [self.extensionContext completeRequestReturningItems:nil completionHandler:nil]; once the share is done, and as I understand it, that should dismiss my UI. I've also tried [self.view removeFromSuperview] without any luck.
Happens on Simulator and Device. Is there something I'm missing?
Edit: This is what the view hierarchy of a simple app I built to test sharing looks like in Reveal before and after sharing. The app has two buttons: share text and share url, each of which bring up a standard share sheet.
Before
http://joshh.is/1utYnKS
After
http://joshh.is/1rdVo34
Ok, I don't know why it took me 10 hours to realize that I was not including a call to super inside of my beginRequestWithExtensionContext: method.
I don't know what other problems that caused, but it certainly caused my problem above.

ios - how to create a screen with a lot of text and buttons and not use UIWebView

I can not use UIWebView because I want the text to be accessible even if the user does not have Internet access on their phone. Also, I will need to have buttons to other screens on the app and I think that is not possible with UIWebView (right?)
Is there a way for me to edit the xml of the screen directly inside Xcode? My requirement is to have about 10 sections with header labels and buttons before each, so if I have to adjust it on the storyboard screen, it will be a bit nightmarish.
What is a reasonable approach for me here? I think only to edit the xml by hand and hardcode it with styles and text, right?
several things here:
webviews only need an internet connection if you are downloading the content for the view (which doesnt seem like what you want anyway, aren't you just building it locally?)
you can make the buttons in a webview do whatever you want. See this answer.
What is so complex about this UI that you can't just build it the regular way in code or IB?
Just because you consider using a UIWebView it doesn't mean you are restricting your application functionality to internet access.
You can just as well have HTML documents in the application bundle that you display in a webview. This is basically what PhoneGap is doing.
If you don't want to use webviews then nothing is stopping you from using UIViews, UILabels, UIImageViews etc and compose your app how you want.

iPhone OS 3.2; PDF rendering; User Interaction

I'd need to create a iPad-app which would be rendering multiple PDF-Files (one file contains one page).
Each page should be scrollable, zoomable and if the user taps on a part of the PDF a website or photo gallery should popup.
Currently i think i could do that either with:
A. UIWebView
Displays the pdf's nicely, scrolling and zooming works. But it looks like a lot of trouble to realize the clickable parts of the PDF.
I don't know if i could use CGPDFContextSetURLForRect
Getting the touch-events from UIWebView to do something like CGPDFContextSetURLForRect my self looks like it would be some "quite bad" hack. See: http://github.com/psychs/iphone-samples/blob/master/WebViewTappingHack/Classes/PSWebView.m
B. Quartz
I found some resources describing how to display PDF's directly via Quartz.
See:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
This would allow using CGPDFContextSetURLForRect
But i have no idea if this would - like UIWebView - support scrolling and zooming out of the box?
Anybody could enlighten me on this please?
Thanks for your time!
[Edit: changed 3.0 to 3.2]
[Edit: my "solution"]
Hi!
I could come up with a working implementation for PNG but not for PDF's.
[Abstract]
My sollution was Rendering the content, intercepting the touches on it, retreiving the coordinates relative to the displayed content if it is one touch and finally looking up what to do from a mapping containing the interactive areas as coordinates and what to do if they get clicked.
[For PNG]
It was way more cumbersome to implement somethink like that than i would have imagined...
And the implementation i got working depends heavily on the content you want to display because this does work for UIImageView but i could not get it working with UIWebView.
First you need a UIScrollView and UIImageView to render the content and support scrolling/zooming.
Then you need to implement some handling to get the touches/gestures you are interested in.
See: developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Listings/1_TapToZoom_Classes_TapDetectingImageView_h.html
This sample from apple provides everything you need to get this part working.
As a bonus it also takes care about transforming the coordinates relative to the viewport of the content which is very handy! (else you would only know where the tap happend on the screen wich only one half of the info you need if your content is zoom-/scrollable)
[For PDF]
If you want to do this with PDF the first thing would be that you need to use a UIWebView (probably you could do it via Quartz or something else too)
Getting the touches with a UIWebView is a real pain!
There are a lot of ways proposed on the web and besides one noone did what it should do.
After days of googling i found this gem: cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
So... subclassing UIWebView does not get you anywhere unlike UIImageView and you have to subclass UIApplicationMain and implement its method for handling touch-events.
Here you could reuse some of the "Touch-Handling-Stuff" from the apple-examlpe from above.
Now you would need to translate the coordinates of the touch to your content if it is zoom-/scrollable. UIWebView DOES NOT do this for you unlike UIImageView!
I could never figure out how to get the required information(what part of the content at which zoomlevel) from a UIWebView to translate the coordinates but due to the changed requirements from PDF to PNG i didn't care to get it working too much.
hope this helps.
Using the CGPDF* operators will allow you to write a UIPDFView, which operates exactly as UIImageView but uses a PDF as the source image. Create your own custom subclass of UIView and implement drawRect: to, eventually, call CGContextDrawPDFPage. Based on a quick Google search (because I know the keywords), this page seems to explain that side of things quite well.
You can then directly substitute your custom UIView subclass for the UIImageView and proceed exactly as you have with the PNG solution.

Resources