I'm having an issue with a action to a Facebook page.
The currentVriend is a NSObject Class.
I get the error: too many arguments to method call expected 1 have 2
-(void)goFB
{
NSURL *url = [NSURL URLWithString:#"fb://profile/%g",self.currentVriend.fbid];
[[UIApplication sharedApplication] openURL:url];
}
What am I'm doing wrong?
Maybe make another String?
Thanks
I believe you are missing the correct NSString method
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"fb://profile/%g",self.currentVriend.fbid]];
Related
I am receiving a url from a server request, I made a button , when pressed, safari must open and go to the link,
My code below:
- (IBAction)openFeedbackWebViewPresser:(id)sender {
NSString *feedbackUrl = self.getConfig.feedbackURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
}
If I print the feedback url , its as below:
https://xxx.xxxxx.com/CRM/feedback#/1715171559ae979371687#/10306
I tried to use another way:
NSURL *url = [NSURL URLWithString:feedbackUrl];
[[UIApplication sharedApplication] openURL: url];
the url is returning nil, knowing that the feedbackUrl contains a url.
Any idea whats wrong?
Thanks
Might be your string url is containing any spaces or any other special characters that must be encoded. like below
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
hope it helps.!!!
This might be happening because of the special characters that must be encoded. The following encoding works for me-
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
This is the code to open the link in browser, Hope this help
- (IBAction)emailButton:(id)sender {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:self.emailLabel.text]];
}
I am stuck in a very obvious method of NSURL class URLWithString I am passing a string and while creating URL it returns nil, my string is perfect. When ever I uses same string in browser then it is working fine. I am using following method to convert NSString to NSURL:
NSURL *url = [NSURL URLWithString:urlString];
//urlString is my perfect string
I have also tried to encode my string first by using following
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// using this line my output string when I log url is "url%10%10%10%10%10%10..."
%10 becomes the suffix of my url with around 100+ repetition.
If any one has idea what %10 is or what can be done to overcome this problem.
here is my urlString:
Use below code to resolve your problem.
NSString *str = msgDetail[#"thumbnail"];
NSString* webStringURL = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:webStringURL];
yes what was wrong in my string were many unidentified characters due to copying from internet site, if anyone of the reader facing this issue can copy and paste your string as see the count. And confirm.
Thanks
Try below solution
NSURL *url = [NSURL URLWithString:[urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Check it..!
i have a class which connect with a web service, and i created this method :
+(listingObject *) getDetailsForId : (NSString *) id {
NSURL *url=[NSURL urlwithstringFormat : #"htt://mywebservic&id=%#",id];
}
it does not work plz some help
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://example.com/%#", id]]
...is a contrived example. It may be easier for readability to create your string on a separate line.
I have an NSURL of the form
"http://abc.def.com:1234/stuff/"
and I want to append to it so the final url is like this
"http://abc.def.com:1234/stuff/?x=123".
But if I do this
url = [NSURL URLWithString:#"http://abc.def.com:1234/stuff/?"];
url = [url URLByAppendingPathComponent:#"x=123"];
Then the result is
http://abc.def.com:1234/stuff/x=123?
(its the same result if URLByAppendingPathExtension is used).
But if I do this
url = [NSURL URLWithString:#"http://abc.def.com:1234/stuff/?"];
url = [url URLByAppendingPathComponent:#"x=123"];
Then the result is
http://abc.def.com:1234/stuff/%3Fx=123
(also the same result if URLByAppendingPathExtension is used).
Neither of which is what I am after. How do I get a final result of "http://abc.def.com:1234/stuff/?x=123" ?
I think the simplest answer here is to create a new URL using the old one as the base URL.
url = [NSURL URLWithString:#"?x=123" relativeToURL:url]
Here is a unit test that checks the logic
- (void)testCreatingQueryURLfromBaseURL
{
NSURL *url = [NSURL URLWithString:#"http://foo.com/bar/baz"];
url = [NSURL URLWithString:#"?x=1&y=2&z=3" relativeToURL:url];
STAssertEqualObjects([url absoluteString], #"http://foo.com/bar/baz?x=1&y=2&z=3", nil);
}
Create your actual NSURL object last, from an NSString that you build up as needed:
NSString *urlString = #"http://www.site.com/";
if (some condition)
urlString = [urlString stringByAppendingString:#"?x=123"];
NSURL *url = [NSURL URLWithString:urlString];
My code is like this :
NSString *urlStr = [NSString stringWithFormat:#"https://xxx.xxx.xx.xx/Pages/Service/FMService.svc/FileAudit?user=%#&pass=%#&fileId=%d&isAudited=1&opinion=%#",appDelegate.user.userName,appDelegate.user.password,self.todo.fileId,self.opinion];
NSLog(#"URL=%#",urlStr);
NSURL *url = [NSURL URLWithString:urlStr];
And the url = (NSURL *) 0*00000000#"< nil >"
how can I work it out? thank you in advance!
For debugging purposes, I would build up urlStr piece by piece instead of combining five NSStrings all at once. Put in an NSLog(#"%#", urlStr) statement after each addition to urlStr. This will reveal which piece of the puzzle is causing the problem.