Array in webview (going to a random site) - ios

I can't figure out how to put multiple sites in an webview. But basically I have one webview, and i want it to load up random sites every-time you go to. I looked at another question like this, but it opened up Safari, i dont want it to open up safaria, i want to stay inside the app in a webview.
This is the questoin i was looking at earlier: Random websites button
It worked good. But i need it to stay in the app in the webview.

Change :
if ([[UIApplication sharedApplication] canOpenURL:randomURL])
[[UIApplication sharedApplication] openURL:randomURL];
On:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: randomURL];
[self.webView loadRequest:request];

Related

SFSafariViewController doesn't open url in mobile mode

I have simple code
NSURL *url = [NSURL URLWithString:#"https://en.wikipedia.org/wiki/Cat"];
if ([SFSafariViewController class] != nil) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:url];
[self presentViewController:sfvc animated:YES completion:nil];
} else {
[[UIApplication sharedApplication] openURL:url];
}
I've tested on iOS 9.3. When I first open url I can see the page in mobile mode.
(Picture 1)
Next I click Desktop. And I can see this page (Picture 2)
(Picture 2)
I restarted application and SFSafariViewController still opens page in Desktop mode (Picture 2).
Can I force open the url in the mobile mode using SFSafariViewController and How Can I do this?
The "Desktop" link in this context means the user will see what s/he would normally see when clicking on their Macintosh or PC. This is expected behavior.
If you suspend and then resume the application, especially when SFSafariViewController is visible to the user, the app will resume on the same page where it was left off, unless you tell it to re-open the original URL (which you can do by having your application delegate watch for applicationWillEnterForeground: and then force reload the view controller).
if it were working fine, then all you need to do is to click mobile view in wikipedia footer, otherwise rebuild your app and clean it, it will restore the default behavior
The final solution that I found, It's using specific links with a prefix (m.) that the server supports, It will force open the urls with the mobile mode:
NSURL *url = [NSURL URLWithString:#"https://en.m.wikipedia.org/wiki/Cat"];

Programmatically navigate to iOS main settings app, not the app specific settings page

I have this code snippet that will open my app specific settings screen.
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
But I want the user to be taken to the main iPhone Settings screen instead of app specific screen. I have been searching for this over the last few days and not able to find a way. Is it possible to do this navigation?
I tried this in Swift and It took me to main settings screen.
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)

how to open iPhone call screen keypad with number, when click on the button in iOS?

I have call button in my view controller in my application. when i will click on call button, it will show my iPhone call keypad with some number.
I am not getting any solution for this. Please help me.
Thank-you
Before you think I am, I am not the Popeye that has supplied the other answer.
Right down to my answer. There are a couple of ways you can do this
// Pick one of the two ways from below, one will return you to the app afterwards the other will not.
// This version of of creating the number will open the dialer but will not return you to the app afterwards.
NSURL *phoneNumber = [NSURL urlWithString:[NSString stringWithFormat:#"tel://%#", yourNumberString]];
// Whilst this version will return you to your app once the phone call is over.
NSURL *phoneNumber = [NSURL urlWithString:[NSString stringWithFormat:#"telprompt://%#", yourNumberString]];
// Now that we have our `phoneNumber` as a URL. We need to check that the device we are using can open the URL.
// Whilst iPads, iPhone, iPod touchs can all open URLs in safari mobile they can't all
// open URLs that are numbers this is why we have `tel://` or `telprompt://`
if([[UIApplication sharedApplication] canOpenURL:phoneNumber]) {
// So if we can open it we can now actually open it with
[[UIApplication sharedApplication] openURL:phoneNumber];
}
Hope this helps if you have any questions please just ask.
iPhone SDK doesn't gives you direct access to dial numbers from the app.So,you can't do this,but there is a way to achieve this.
-> Have a TextField(yourPhoneNumber) with keyBoardType UIKeyboardTypePhonePad.
-> [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#",yourPhoneNumber.text]]];
Hope this will help you out.

Stopping a video stream when UIViewController is closed

I have a UIViewController with a UIWebView with the URL pointing to a video on my website which loads and streams fine when the page is opened.
I then have a Back button on the same page to take me back using a segue. However if I use this button to return the video continues to play in the background. I presume the segue does not actually close the view but just pushes the new view in front.
Can anyone advise me as to what I ought to do to either close the view or to stop the video downloading when the button is pressed?
In viewWillDisappear: you can call stopLoading on the web view, which will stop any requests that are still loading, followed by loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]] to remove any loaded content. You can also send nil to loadRequest: (which as of iOS 6 has the same effect as the about:blank request) but that behavior isn't documented and could change in future releases.
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.webView stopLoading];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
}

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.

Resources