Facebook Authorization dont work in iPhone app Xcode - iphone

I have a project in XCode, which contains two targets, one at a lite version and the other to the full version. In both cases it requires the user to apply for permission to publish to Facebook.Both versions handle the same consumption Facebook ID.
In the full version opens a window asking for authorization of Facebook and if you authorize it, returns to the application whose I'm developing.
The Lite version is where the problem arises, it calls the authorization request window on Facebook, and if you press Authorize application does not return to the Lite app.
In both cases, the code is:
BOOL didOpenOtherApp = NO;
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:#selector(isMultitaskingSupported)] && [device
isMultitaskingSupported]) {
if (tryFBAppAuth) {
NSString *fbAppUrl = [FBRequest serializeURL:kFBAppAuthURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}
if (trySafariAuth && !didOpenOtherApp) {
NSString *nextUrl = [NSString stringWithFormat:#"fb%#://authorize", _appId];
[params setValue:nextUrl forKey:#"redirect_uri"];
NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
}}
Thanks

I've got the same problem but i've solved using the Sharekit.. It's fantastic because you can share almost everywhere in just few lines of code and it's all done, this will make all you need for you..
Facebook, Twitter, Delicious, Instagram, Evernote and other services are already supported and if you don't care about this services, well, you can delete this file and the framework will work the same. Isn't it enough? You can make your own design with pre-imposted file in the framework to make this work the best with your app design..
Hope it helps!

Related

Google Maps link for iOS

I want to have a link to a Google Map on our company mobile website. The problem is, if I make a link, it takes you to the Google Maps website. It needs to open up the app.
I have found out that if you start the url with "comgooglemaps://" it will open google maps. However, this poses the problem that if a iOS user does not have Google Maps installed the link will not work.
Is there a way to open Google Maps if it is installed, but open the browser if not (I don't believe you can open Apple Maps from a website due to the nature of their API)
Thanks
EDIT: Just a heads up, this is being done on a website, not an app. So it needs to be done through HTML, Javascript, PHP etc. NOT a programing language.
Have a look at the Apple Maps Links page.
Basically you link to maps.apple.com and it redirects to Google Maps if needed. Here's an example from the page:
http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino
With latitude, longitude and zoom:
http://maps.apple.com/?ll=53.01,6.01&z=15
Check this Link
You can use this method with url scheme for google map app. (comgooglemaps://blahblah)
[[UIApplication sharedApplication] canOpenURL:(NSURL*)foo]
It will return BOOL value.
Try this to move google map and set route
NSString* addr = nil;
addr = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", destinationLat,destinationLong];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
Try this code
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"comgooglemaps://"]]) {
NSString * url = [NSString stringWithFormat:#"%#%#,%#",#"http://maps.google.com/maps?q=",#"75.14524",#"12.1521"];
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:url]];
}

Open a facebook link by native Facebook app on iOS

If the native Facebook app is installed on the iPhone. How do I open a facebook link into the native Facebook app from my app. In the case of opening by Safari, the link is same as:
http://www.facebook.com/AlibabaUS
Thank you.
Here are some schemes the Facebook app uses, there are a ton more on the source link:
Example
NSURL *url = [NSURL URLWithString:#"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];
Schemes
fb://profile – Open Facebook app to the user’s profile
fb://friends – Open Facebook app to the friends list
fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
fb://feed – Open Facebook app to the News Feed
fb://events – Open Facebook app to the Events page
fb://requests – Open Facebook app to the Requests list
fb://notes – Open Facebook app to the Notes page
fb://albums – Open Facebook app to Photo Albums list
If before opening this url you want to check wether the user fas the facebook app you can do the following (as explained in another answer below):
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
}
else {
//Open the url as usual
}
Source
http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
Just use https://graph.facebook.com/(your_username or page name) to get your page ID and after you can see all the detain and your ID
after in your IOS app use :
NSURL *url = [NSURL URLWithString:#"fb://profile/[your ID]"];
[[UIApplication sharedApplication] openURL:url];
To add yonix’s comment as an answer, the old fb://page/… URL no longer works. Apparently it was replaced by fb://profile/…, even though a page is not a profile.
I did this in MonoTouch in the following method, I'm sure a pure Obj-C based approach wouldn't be too different. I used this inside a class which had changing URLs at times which is why I just didn't put it in a if/elseif statement.
NSString *myUrls = #"fb://profile/100000369031300|http://www.facebook.com/ytn3rd";
NSArray *urls = [myUrls componentsSeparatedByString:#"|"];
for (NSString *url in urls){
NSURL *nsurl = [NSURL URLWithString:url];
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
break;
}
}
The break is not always called before your app changes to Safari/Facebook. I assume your program will halt there and call it when you come back to it.
I know the question is old, but in support of the above answers i wanted to share my working code.
Just add these two methods to whatever class.The code checks if facebook app is installed, if not installed the url is opened in a browser.And if any errors occur when trying to find the profileId, the page will be opened in a browser. Just pass the url(example, http://www.facebook.com/AlibabaUS) to openUrl: and it will do all the magic. Hope it helps someone!.
NOTE: UrlUtils was the class that had the code for me, you might have to change it to something else to suite your needs.
+(void) openUrlInBrowser:(NSString *) url
{
if (url.length > 0) {
NSURL *linkUrl = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:linkUrl];
}
}
+(void) openUrl:(NSString *) urlString
{
//check if facebook app exists
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
// Facebook app installed
NSArray *tokens = [urlString componentsSeparatedByString:#"/"];
NSString *profileName = [tokens lastObject];
//call graph api
NSURL *apiUrl = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#",profileName]];
NSData *apiResponse = [NSData dataWithContentsOfURL:apiUrl];
NSError *error = nil;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:apiResponse options:NSJSONReadingMutableContainers error:&error];
//check for parse error
if (error == nil) {
NSString *profileId = [jsonDict objectForKey:#"id"];
if (profileId.length > 0) {//make sure id key is actually available
NSURL *fbUrl = [NSURL URLWithString:[NSString stringWithFormat:#"fb://profile/%#",profileId]];
[[UIApplication sharedApplication] openURL:fbUrl];
}
else{
[UrlUtils openUrlInBrowser:urlString];
}
}
else{//parse error occured
[UrlUtils openUrlInBrowser:urlString];
}
}
else{//facebook app not installed
[UrlUtils openUrlInBrowser:urlString];
}
}
swift 3
if let url = URL(string: "fb://profile/<id>") {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],completionHandler: { (success) in
print("Open fb://profile/<id>: \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open fb://profile/<id>: \(success)")
}
}
If the Facebook application is logged in, the page will be opened when executing the following code. If the Facebook application is not logged in when executing the code, the user will then be redirected to the Facebook app to login and then after connecting the Facebook is not redirected to the page!
NSURL *fbNativeAppURL = [NSURL URLWithString:#"fb://page/yourPageIDHere"] [[UIApplication sharedApplication] openURL:fbNativeAppURL]
Just verified this today, but if you are trying to open a Facebook page, you can use "fb://page/{Page ID}"
Page ID can be found under your page in the about section near the bottom.
Specific to my use case, in Xamarin.Forms, you can use this snippet to open in the app if available, otherwise in the browser.
Device.OpenUri(new Uri("fb://page/{id}"));
Previous method fb://profile/[ID] is not working.
try fb://profile?id=[ID]
Example of usage:
// Open Profile or page
// To open in Application
if UIApplication.shared.canOpenURL(URL(string: "fb://profile?id=vikramchaudhary.ios")!) {
UIApplication.shared.open(URL(string: "fb://profile?id=vikramchaudhary.ios")!, options: [:], completionHandler: nil)
} else {
// To open in safari
UIApplication.shared.open(URL(string: "https://facebook.com/vikramchaudhary.ios/")!, options: [:], completionHandler: nil)
}
This will open the URL in Safari:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.facebook.com/comments.php?href=http://wombeta.jiffysoftware.com/ViewWOMPrint.aspx?WPID=317"]];
For the iphone, you can launch the Facebook app if installed by using a url starting with fb://
More information can be found here: http://iphonedevtools.com/?p=302 also here: http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
Stolen from the above site:
fb://profile – Open Facebook app to the user’s profile
fb://friends – Open Facebook app to the friends list
fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
fb://feed – Open Facebook app to the News Feed
fb://events – Open Facebook app to the Events page
fb://requests – Open Facebook app to the Requests list
fb://notes - Open Facebook app to the Notes page
fb://albums – Open Facebook app to Photo Albums list
To launch the above URLs:
NSURL *theURL = [NSURL URLWithString:#"fb://<insert function here>"];
[[UIApplication sharedApplication] openURL:theURL];
2020 answer
Just open the url. Facebook automatically registers for deep links.
let url = URL(string:"https://www.facebook.com/TheGoodLordAbove")!
UIApplication.shared.open(url,completionHandler:nil)
this opens in the facebook app if installed, and in your default browser otherwise

Open Facebook i safari if the Facebook native app is not installed

I'm making an application where i would open Facebook native app from within the app.
That problem i have sold with this
NSString* urlString = #"fb://groups/";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
But if the native app isn't installed it should open Facebook in the native safari app on the iPhone. That is my problem?
Is there anyone that could help me with that?
NSString fbURL = #"fb://group/5385407511";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:fbURL]];
if(canOpenURL) {
[[UIApplication openURL:[NSURL urlWithString:fbURL]];
} else {
[[UIApplication openURL:#"http://facebook.com"];
}
It's a very bad idea to write your app in a way which relies on Facebook's native app not changing its internal structure, your app could break at any moment.
That said, if you must do this for some reason, you can check if the Facebook app is installed by checking an fb:// URL with UIApplication's
- (BOOL)canOpenURL:(NSURL *)url

How to lunch App-Store with in my iPhone application with list of application of any particular company?

NSString *str = #"itms-apps://itunes.apple.com/in/artist/quizmine-com/id356028414?uo=4";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:str]];
Above code is working fine in my iPad application but it is not working in my iPhone application why? Can some one help me?
After lunch iTunes Store it through's some message "Your request is not complete".

Direct "rate in iTunes" link in my app?

I've seen posts here on Stackoverflow that describe how to allow users to be directed to apps on the app store.
Is there a way to link directly to the rating and comments form in the App Store?
This IS possible using the technique described on this blog:
http://www.memention.com/blog/2009/09/03/Open-Reviews.html
basically you call UIApplication openURL with the following:
NSString* url = [NSString stringWithFormat: #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%#", myAppID];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
To get your app ID before your app is available in the app store, use iTunesConnect to define your new app - give it a name, description, icon, screenshots, etc. Once defined, you can get the Apple ID from the Identifiers section for the app.
EDIT:
Here is a secondary url/method that works:
NSString* url = [NSString stringWithFormat: #"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%#&pageNumber=0&sortOrdering=1&type=Purple+Software&mt=8", appid];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url ]];
I believe the difference between the two is that the first technique (itms-apps://) will launch the App Store app directly while the second one (http://) will launch it indirectly via a redirect resulting from the http web URL. This would have to be confirmed; this is only my recollection.
Answers here are outdated.
This works on my end (Xcode 5 - iOS 7 - works only on Device, not simulator!):
itms-apps://itunes.apple.com/app/idYOUR_APP_ID
For versions lower than iOS 7 use the old one:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=YOUR_APP_ID
Simple method that I am using is;
-(void)rateApp {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[#"itms-apps://itunes.apple.com/app/" stringByAppendingString: #"id547101139"]]]; }
You can also use SKStoreProductViewController as an alternative. It will open the store in your app. You may like it better than opening another app, especially on iPads.
Thanks to Ahment swift version:
UIApplication.sharedApplication().openURL(NSURL(string: "itms-apps://itunes.apple.com/app/id951334398")!)