Prevent URLS in UIWebView from opening Yelp (or other) Apps - ios

I am loading a yelp URL into a UIWebView and want to display the mobile website instead of automatically opening Yelp App. Behavior is as expected in my simulator, but goes to yelp on my phone since I have the yelp app installed.
Below is my code to load the URL:
NSString *fullURL = #"http://yelp.com/search?find_desc=coffee&find_loc=union+square";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_yelpView loadRequest:requestObj];

It can be because the yelp web page could ask about the redirect with some custom URL scheme which then is recognized by Yelp app.
You should debug which requests your web view performs during the loading of Yelp web page.
try to set a delegate to your web view and check which requests it performs with this delegate callback:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

Related

UIWebview loadRequest not working only in iPhone X

I am trying to load a URL using webView in Objective C. I tried "https://www.tidecleaners.com/cincinati-pricing" and it works fine for all devices. But not working only in iPhone X.
Here its my code,
NSString *fullURL = #"https://www.tidecleaners.com/cincinati-pricing";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.WebView_O.delegate = self;
[self.WebView_O loadRequest:requestObj];
According to the Apple docs, error -1007 means NSURLErrorHTTPTooManyRedirects, i.e. the HTTP connection failed due to too many redirects.
Maybe the WebView implementation of the iOS version on your iPhone X is less tolerant to redirects than on older devices. However, this seems to be a server issue, and you probably won't be able to do much about it on the client side.
However, to get more information about the issue, you can enable a more verbose network log:
Open your scheme in Xcode.
Select Runon the left, and the Arguments tab on the right.
Add CFNETWORK_DIAGNOSTICS to the environment variables, and add 1, 2, or 3 as a value (depending on the verbosity you want).
Hopefully, the logs will then tell you a bit more about the error.

Communicating iOS chat service with a web chat service

I'm searching for a cross-platform chat service that supports mobile (Android and iOS), and Desktop. I've looked into a few sites that offer chat services, but none of them seem to be what I'm looking for in terms of features. So I've decided to try to create an iOS application that will connect to a service that we will use for the desktop version.
That was just a bit of background info, but here's the question:
I am creating a url request in order to send information to the server that will handle and store my url request like so:
-(IBAction)clickedSendButton:(id)sender
{
urlReq = [NSString stringWithFormat:#"%#/mobile/PrivateChatMsgSending/?sid=%#&skey=%#&rid=%#&msg=%#",domain,((ApplicationAppDelegate *) [UIApplication sharedApplication].delegate).loggedProfileID,((ApplicationAppDelegate *) [UIApplication sharedApplication].delegate).loggedSessionID,receipientProfileId,txtFldChat.text];
NSURL *url = [NSURL URLWithString:[urlReq stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
connection = [[[NSURLConnection alloc] initWithRequest:urlrequest delegate:self] autorelease];
[self ShowIndicatorView:#"Sending..."];
}
So would I be able to pass these parameters to my php script on the server side all while being compatible with my desktop version? Is there anything within my application that could potentially inhibit my user's from receiving messages from desktop users? What might be a better solution to creating a multi-platform messaging service?

Not able to load facebook fan page wall in UIWebview

In my app, I am trying to display Facebook fan page wall (eg.https://m.facebook.com/DonaldDuck) in the UIWebView. But white screen gets displayed and getting error as:
Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “m.facebook.com” which could put your confidential information at risk."
I have found the same issue as stackoverflow1.
I have tried this solution.
Also tried below links to display Facebook fan page wall.
http://m.facebook.com/DonaldDuck?v=wall
http://m.facebook.com/DonaldDuck?v=feed
Code:
NSURL *url = [NSURL URLWithString:FACEBOOK_LINK];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[requestObj setValue:#" Safari/537.1" forHTTPHeaderField:#"User_Agent"]; // Line 1
[fbWebView setDelegate:self];
[fbWebView loadRequest:requestObj];
Above Line 1, If I use then I am able to see wall page.But this is private api and i have to submit this app on apple store. So, i guess this will not work. :(
Any idea how to resolve this issue on iPad? (It works with iPhone UIWebView)

Display a local web page in a UIWebView

I am trying to display a local web page in a UIWebView. The local web page is a PHP file and stored in the Supporting Files folder then a folder I created called webpages. I tried this code but it doesn't work.
#synthesize web;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"php" inDirectory:#"web"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[web loadRequest:request];
[web setDelegate:self];
[web loadRequest:request];
}
You can not load PHP file in UIWebView, Because PHP needs server to run.
You can't run a local php file through UIWebView. PHP is a server side scripting language. OS X (and Windows) don't know how to interpret php code.
It seems to be an iPhone app your making, and running local php in your iPhone app is a no-go, and will continue to be for the foreseeable future.

iOS Cache Content from a UIWebView

I'm trying to find a way to get a UIWebView to cache an entire web page while one wifi and view it from the cache while connected to 3G, but then reload and recache while on WiFi again.
Are the any APIs or anything to do this?
Cheers
regardless of 3G or WIFI you can use NSURLRequestReturnCacheDataElseLoad with your NSURLRequest which caches webpage otherwise load.. you could create a check for your 3G status
here is the usage of NSURLRequestReturnCacheDataElseLoad
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
and load your data returned from webpage by using loadHTMLString in UIWebView

Resources