iOS url multiple statements - ios

I have recently discovered that there is no way for me to access mysql with the pre defined iOS libraries.
So I have started making an app that has a web viewer (hidden) and will visit a url to pass the information to the database.
But I am having trouble making it so it visits a url that contains multiple variables from my objective c code my example is below.
NSURL *url = [[NSURL alloc] initWithString:#"http://webpageurl.com/updatelocation.php?friendsphonenumber=%#&yourphonenumber=%#&message=%#", _friendsPhoneNumber.text, _yourPhoneNumber.text, _message.text];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[self.WebView loadRequest:request];
This is what the url should come out looking like
http://webpageurl.com/updatelocation.php?friendsphonenumber=1112223333&yourphonenumber=1112223333&message=hioehfoi
But my code is returning a error and I am a little unsure why any and all help is greatly appreciated.

Related

iOS dropbox sdk / core api - listing public folder contents without authorization

I've tried checking on stackoverflow and on the api docs, but couldn't find any info pertaining to this particular question.
What I'm trying to do is getting the public folder contents of a particular dropbox account (like the /metadata function of the api), without the need to authorize/link to dropbox.
I know "/metadata/link" allows you to get metadata of a particular link without user authorization, but I couldn't find a way to get regular metadata and file listing...
Actually it doesn't even need to be a public folder (as I've read recently that dropbox discourages developers regarding relying on public folders for apps), it can just as well be a regular folder through its shared link or anything of the kind...
I'm using api v1 (but can consider changing to v2 if this is impossible with v1), although I'm not even sure if this is at all possible.
Thank you!
For future reference, if anyone needs this as well, here's how I did it:
NSString *parameters = [NSString stringWithFormat:#"?link=%#&client_id=%#&client_secret=%#",fileUrl, appKey, appSecret];
NSString *sharedPath = [NSString stringWithFormat:#"%#/%#",#"https://api.dropbox.com/1/metadata/link", parameters];
NSURL *url = [NSURL URLWithString:sharedPath];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
theRequest.timeoutInterval = 5.0;
theRequest.HTTPMethod = #"POST";
NSData * resData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
Use NSJSONSerialization to parse resData and refer to the api documentation for json fields, and that's it.
For the sake of simplicity showing it here I used synchronous request, but it can just as easily be done with asynchronous connection delegates.

How to display the Authentication Challenge in UIWebView for local network url?

I am trying to access a secure for local network url through UIWebView. When I access it through safari, i get an authentication challenge but the same does not appear in my UIWebView in the application. How can I make it appear?
E.g. http://292.168.1.54/TestWeb/Test.pdf
This url working in safari browser but the same url does not appear in my UIWebView.
Any pointers, sample code or links will be very helpful. Thanks a lot.
There are two ways to get to the authentication (in your case probably basic auth) challenge.
-[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:] will give you the request. Now you just start a second request to the same URL and use [NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge:] to get the challenge. Then you present a dialog and ask the user for credentials. Save the credentials in NSURLCredentialStorage and then reload the page.
Create a subclass of NSURLProtocol that handles http and https. Similar to this answer and get the authentication challenge there.
I hope this code will help you.
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.webView.delegate = self;
NSURL *url = [NSURL URLWithString:#"http://skinC.com/abc/"];// here you can write your url that you want to open
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self setNeedsStatusBarAppearanceUpdate];}

How to get WOEID without using yahoo services?

Is there any other alternative to get WOEID of a place, other than yahoo services? Is there any third party library which is free?
You can get it by making a query request using the city name you want and hitting yahoo service with code like this:
NSString *request = [NSString stringWithFormat:#"http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text=\"%#\"&format=xml", cityName];
NSString *encRequest = [request stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *URL = [NSURL URLWithString:encRequest];
I've put the complete example for this in github, but this is a solution just for testing purposes. You should use the official way (and pay if needed) for a commercial app.

PhoneGap/ChildBrowser - POST App Form to ChildBrowser

I am building an iPhone App using PhoneGap. I am using ChildBrowser plugin.
If I have a form in the App with username/pass, is there anyway I can post those information to an URL like www.mydomain.com/login.php and open it in ChildBrowser?
Please let me know.
Thanks.
You can certainly pass GET parameters to childBrowser.showWebPage().
You could intercept the submit of your form in your app and gather up the field names and values passed (assuming this is a login form, so say username and password) and pass them as parameters to the URL opened in ChildBrowser.
childBrowser.showWebPage('https://www.mydomain.com/login.php?username='+username+'&password='+password)
This is a rather unsophisticated version for demonstration purposes. It wouldn't take much to make it better.
The catch is of course that it is being sent via GET. If your login form is expecting POST and you can't change that, you could have a problem.
Edit:
If POST is your only option, perhaps you would be better off using AJAX to post to the form instead of using child browser.
I was looking for a solution, and ended developing it. This doesn't come out of the box in childbrowser for iPhone.
So, here the code that I added to the plugin.
FYI, data should be a string with the format: arg1=value1&arg2=value2&foo=bar
ChildbrowserViewController
I've added the following method there:
- (void)postURL:(NSString*)url data:(NSString*)data{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: [NSURL URLWithString:url]];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: [data dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];
webView.hidden = NO;}
ChildbrowserCommand
I've added the following code in the showWebPage method:
NSString* method = [ options objectForKey:#"method"];
if ([method isEqualToString:#"POST"]){
[childBrowser postURL:url data:[options objectForKey:#"data"]];
}else{
[childBrowser loadURL:url];
}
HTH!
Milton.

Couldn't get Google custom search results using JSON

I'm developing an application that makes use of Google custom search api as a feature. I added a new custom search and included some sites to search, I was able to do a search and get the results I need, but all of a sudden it stopped returning results. It returns an empty array instead. I didn't alter anything, but it looks like I have a limited number of queries, am I right?
Here's the line of code responsible for query a search word:
NSString *search = [NSString stringWithFormat:#"https://www.googleapis.com/customsearch/v1?start=1&ie=utf8&key=XXXXXX&cx=XXXXX&q=SEARHWORD&alt=json"];
url = [NSURL URLWithString:[search stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLConnection *searchConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
Then the normal steps of parsing the results.
if it was working fine, and then stopped all of a sudden, you may have hit the limit.
You can double check by copy-pasting
https://www.googleapis.com/customsearch/v1?start=1&ie=utf8&key=XXXXXX&cx=XXXXX&q=SEARHWORD&alt=json
in a browser and seeing the response

Resources