I have an app which uses a UIWebView and cordova/PhoneGap. One section of the app has a 'Download Calendar' feature, which has been giving me a lot of issues on the native iOS side. The basic function of Download Calendar is an ajax call (type: POST) which returns formatted ics data. In mobile safari, this functions perfectly. A table view will slide up from the bottom and give me the option to add the listed events to my phone's calendar. I think this is just how safari normally handles ics files. Now for my issue...
UIWebView doesn't seem to want to behave this way. When I tap "Download Calendar" nothing happens. To get the ics data, I used an NSURLConnection to get the response, and put it in an NSData structure called webData. With _webData, I'm making this call:
[self.webView loadData:_webData
MIMEType:#"text/v-calendar"
textEncodingName:#"utf-8"
baseURL:[NSURL URLWithString:#"calshow://"]];
In my shouldStartLoadWithRequest: method, I'm telling any 'calshow://' urls to open the calendar, but I don't think this gets me anywhere, since I can't pass the NSData along with it. My main question right now is, can my UIWebView mimic how safari handles this ics data? If not, can I do anything useful with this NSData?
BEGIN:VCALENDAR\r\nPRODID:-//bobbin v0.1//NONSGML iCal
Writer//EN\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT...
UPDATE: I was able to get this working in a UIDocumentInteractionController, where it displays the dates and times exactly how safari would handle the data, however, there isn't an "Add All" button or an "Open in Calendar..." option. The UTI is correctly set to com.apple.ical.ics, but I'm not presented with any usable options in the view.
This link may offer a solution. Appears UIDocumentInteractionController works with .ics files, but I haven't verified.
Related
I have the opposite problem of iOS open YouTube App with query (url schemes).
Basically I have a URL such as https://youtu.be/A4yitOx14Bg. When the user taps it, or when I open URL, it normally opens up in the YouTube app. The user can usually customize this behavior with a non-obvious gesture. Namely they can tap and hold the link, and then choose to “Open in YouTube” or “Open in Safari”.
Is there some form of the URL that will always force it to open in mobile Safari, and not require user intervention?
I found this site which has a bunch of different formats: https://gist.github.com/rodrigoborgesdeoliveira/987683cfbfcc8d800192da1e73adc486
Pasting it into notes reveals that the only formats that force a page to load into safari are the youtube-nocookie.com urls. This is an official URL from Google, mentioned here.
Thus the same link above can be changed to https://www.youtube-nocookie.com/embed/A4yitOx14Bg and it’ll forcibly load in mobile Safari.
I am facing the following problem:
In a web interface, file downloads are triggered with an anchor tag, like this:
<a href="/bla/blabla" download>..</a>
While Safari browser can handle this request and open a dialogue to handle the file, WKWebView treats this just as an ordinary link and does nothing with it. I want to be able to get the file handler dialogue that is normally there when using Safari.
Right now there are 2 problems and I do not see an opening there yet:
I can not detect a click on the element as it is treated just as a normal link. And I can not rely on the URL parameters to detect if it is a file since that is not constantly true.
Even if the URL is defined as a one leading to a file, I can not pass it to Safari since it does not share session info and cookies with my app's WKWebView.
Therefore, I would like to know if there is any opening in handling files in iOS WKWebView. Thank you.
I've managed to open an ics file stored locally, and the UIDocumentInteractionController recognizes it the UTI as com.apple.ical.ics (which is expected). The data displays as I was hoping, for the most part:
I was under the impression from the docs that UIDocumentInteractionController would automatically recognize this ics file type and give some calendar-related options, however, there doesn't seem to be any way for me to add these events to my calendar from this view. Under the "Open in" menu, I see mail and dropbox as options, but not Calendar. If I email it to myself, I then can add the events from the mail app. Am I missing something with how this view works? Mobile Safari handles ics files in a similar way, except there will be an "Add all" button in the title bar. That's exactly how I thought this would behave. I'd prefer not to use EventKit at this point, since I'd just like it to mimic how safari handles the file.
I am running into a situation which I am not sure is possible from technical/design point of view. Please advise.
Here is what I need:
I have an open URL registered for my native iOS app. I expect a request ID to be passed along with it and once hit I open that request.
From within my native iOS app, I need to open a web page in the webview. This page has few buttons in it.
A tap on the button in the webview should open the request inside my app. So, I want to trigger the registered open URL in step #1.
Web page data is dynamic and will change on the fly.
Is this a feasible design. Shall I consider something else.
Any advise/pointers will be appreciated.
This should be possible. Here's a though:
1: Implement the UIWebview delegate method shouldStartLoadWithRequest.
2: when you intercept that your webview is attempting to access the url yourapp://blah-blah-blah you can return NO instead dip into your appdelegate can manually call the function handleOpenURL.
I've seen something similar in the past with supporting oAuth (I believe it was with instagram) within one of our apps. We basically loaded up the login page in a UIWebview and then when we detected the the post login redirect we parsed the oAuth token from the url and called it good.
Good luck
I'm about to work on my first ever iOS app. For the first version, the main goal is to make the app a webview of my website. This is easy so far by just pointing a webview to the proper url. The part I need help with is replacing a Flash video player in the webview with a native video player.
Basically on the website I have a Flash video player that connects to a streaming video server with RTMP. As of now, the website is required to use Flash video (so converting to HTML5 video is not an option). The iOS app should show the website as is, except find the Flash player and replace it with a native video player so that the video playback still works on the iPhone/iPad.
Does anyone have any advice for accomplishing this?
This can be done. It may not be clean and pretty, but here is a possible approach: You are going to need to parse the HTML prior to displaying it.
First, you need to intercept the load request calls of your UIWebView so that you can check to see if it is calling the URL of the page that has the Flash you need to parse out. To intercept the load request call, use the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType: to read the URL.
If the URL matches the URL you need to remove the Flash from, you are going to run code that loads a HTML string that you will parse into the web view (more on that in a minute) and return NO to the webView:shouldStartLoadWithRequest:navigationType: delegate method. This means that when the user tries to go to the page with the Flash in it, we are going to stop the UIWebView from doing its thing and load the view with our own parsed content.
Once you figure out that you need to parse the HTML, you need to get in into a variable that you can work with. To get the HTML of your page as a string:
NSURL *yourURL = [NSURL URLWithString:#"http://google.com"];
NSError *error;
NSString *htmlString = [NSString stringWithContentsOfURL:yourURL encoding:NSUTF8Encoding error:&error];
Once you have the string, to remove the Flash code from your HTML, see this question:
Comment out a string in HTML before UIWebView can display it
Once you have parsed the HTML and gotten rid of your Flash, you can load it into your web view with [webView loadHTMLString:string baseURL:nil];
Finally, you need to insert a native movie player on top of your web view via code. You'll have to deal with screen rotation and sizing and placement of the native player on top of the web view, but that fun I will leave to you.
That is a lot of raw material, but is should get you going on one on possible solution.
So, what you’re asking is to show a WebView inside the native app, and show some native components inside this WebView. This cannot be done.
You will have to build a completely native app for this. Or use HTML5 inside the WebView.