Iphone app that launches a website without url bar - ios

I need to make a simple app for iOS. After opening it, i want it to open up safari with a certain website and that the address bar wouldn't show.
I'm completely new to iOS apps and I couldn't find anything similar from google. Maybe somebody has done it and can share the code or point me to somewhere where I can find it?

You can simply use a UIWebView, which by default doesn't include any controls or an address bar.
Class documentation here
Here is a small example of usage:
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"www.google.ie"]]];
[self.view addSubview:webView];
This will effectively give you a browser view inside your application, without invoking Safari itself.
You can embed this UIWebView in a UINavigationController, or use it anywhere else in your applications view hierarchy.
One final point, the UIWebView class has many delegate methods which you can implement, these methods will be called by the system when a given event happens (URL loads, has errors, etc).

Related

Launching Containing App from UIWebView in Custom Keyboard

Since you can only go the normal route for launching a containing app from a Today extension, and not a Custom Keyboard, I've been trying to do the hacky version of launching a UIWebView and launching the containing app through its URL scheme. Mostly been getting help from this post: launch containing app from iOS8 Custom Keyboard, but I'm not allowed to comment on answers since I'm new to stack overflow.
Anyways, doing it now, the UIWebView is popping up but is just showing a blank white square and not launching the URL scheme. Already tried accessing the URL scheme from Safari, and I know that launches the app, so not sure why its not doing anything. Code I have now in the method following when the right key is pushed is:
let urlkey = NSURL(string: "MYAPP://")
let webAppView = UIWebView(frame: CGRectMake(0, 0, 100, 100))
let request = NSURLRequest(URL: urlkey!)
webAppView.loadRequest(request)
self.view.addSubview(webAppView)
Any ideas for why nothing in the view is loading, or other ways to go about launching a containing app from a custom keyboard appreciated. Using XCode 6.3 and Swift.
It is not possible to launch another app through keyboard-extension.
Other extensions like today-widget-extension can use like below.
NSURL *pjURL = [NSURL URLWithString:#"hostingapp://home"];
[self.extensionContext openURL:pjURL completionHandler:nil];
//https://stackoverflow.com/questions/24019820/today-app-extension-widget-tap-to-open-containing-app
but, nothing happens in the keyboard-extension.
//I guess...
If you get success to implement launching app in the keyboard, the keyboard will not be accepted by Apple.
updated 15/09/14 :
openURL not work in Action Extension
I found some people are trying that, so check this.
Some said their app accepted by apple.(I don't know it's true)

Is it allowed to add a UITabBarItem that opens up Safari?

I want to add a UITabBarItem on the TabBar which when clicked opens up Safari instead of loading its corresponding tab. (Not UIWebView but the app goes to background and opens up Safari instead)
I already know how to do this, but I was wondering if this is allowed by Apple. I know they're OK with using the TabBarItem to trigger other actions such as opening a modal in the app, etc. However I am not sure if it's OK to open a safari.
I am just being cautious because I don't want it to get rejected for this and wait another week.
I don't see a reason why it shouldn't be allowed.
But: it could lead to confusion amongst your users, because they would most likely not expect that touching an item on the TabBar leads to an app switch. I would rather open a webView and offer the additional possibility to open the page in Safari.
There is no harm doing such and it is also allowed by Apple.
But, I would personally suggest to use UIWebView, over Safari navigation. Because it will create unhealthy user experience, where he/she requires to jump around to swith in-between Safari and App. Rather you can open the same link in UIWebView, which will kepp our user in app only.

IPhone UIWebView Application wit AJAX

I'm doing now an iPhone App that encapsulate a web Site inside a UIWebView, the first request is made by the iphone app and it activate the "webViewDidFinishLoad" delegate, but when i press on one of the buttons in the web application inside the UIWebView this delegate is not working, do i need to do anything more in the ViewController or in the Html?
I Think i understand the specific problem: the next calls from the UIWebView are AJAX calls and it does not monitored by the webViewDidFinishLoad, i need some help, anyone know how to handle AJAC calls from UIWebView?
Thanks
Shimon
The right way to do it is to add UIGestureRecognizer to the UIWebView, and in the handler read the UIWebView string, then you can see the AJAX Updates done after the UIWebView was loaded for the first time' solved my problem

open url with back button

I have one little truble.
I want to open URL in my iOS application.
The way I found on the web was :
[[UIApplication sharedApplication] openURL:url];
and it works fine, but this approach close my app and open safari without back button to return in my app. How to achieve this?
I would like something like
MFMessageComposeViewController * picker = [[MFMessageComposeViewController alloc] init];
[self presentModalViewController:picker animated:YES];
Rather than opening the URL in Safari why not just create a new view controller containing a UIWebView?
Show the view controller, pass in the URL, and load the URL into the UIWebView. Something like this:
MyWebViewController *mwvc = [[MyWebViewController alloc] initWithURL:myURL];
[self.navigationController pushViewController:mwvc animated:YES];
Then in MyWebViewController:initWithURL
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL]];
[myWebView loadRequest:request];
Safari is the application provided by Apple itself, so one cannot make change in behaviour of Sarari.
If you require a back button then create your custom UIViewController using UIWebView and place your back button over there.
For back functionality, you can either use UINavigationController or UIViewAnimation.
To get the control back to main native iOS application, you can URLScheme concept. URLScheme concept gives you unique identifier url of a native iOS application.
Check this http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/
It gives you fair idea on the procedure to achieve your requirement.

UIDocumentInteractionController for Open In menu - Doesn't Work

I implemented a UIDocumentInteractionController to send files to other apps. The file is a .txt file.
Here's the code:
UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init];
[interactionController setURL:[NSURL fileURLWithPath:filePath]];
[interactionController setUTI:#"public.text"];
[interactionController setDelegate:self];
[interactionController presentOpenInMenuFromBarButtonItem:actionBarButtonItem animated:YES];
The menu opens fine, showing apps like Pages, Dropbox, etc. as I expect. But when I tap one of them, the Open In menu dismisses and no action is performed (the file is not sent and the target application never opens.
I tried implementing the delegate methods documentInteractionController:canPerformAction: and documentInteractionController:performAction: for triggering copy: and print: calls using the options menu (as opposed to the open in menu) and that pulled up a menu with only Pages listed, but that still did not work.
How might this be resolved?
I found the answer, and it's memory management. I create the UIDocumentInteractionController and then present it, but I don't have it as an instance variable. ARC deallocates it before it has the opportunity to do anything. This includes sending the document to the external app.
This bug didn't appear on the iPhone, but on the iPad it gives an error because the popover architecture works a bit differently and it ends up trying to draw it when it's deallocated. That's what alerted me to the bug.
This bug also appears on iPhone/iPod. Just set:
#property (nonatomic, retain) UIDocumentInteractionController *docController;
and it will be retain and the document passed to the new application.
it's enough to add the following code:
[interactionController retain];

Resources