iOS FaceBook ingegration, Feeds dialog shows blank the first time - iphone

Im using the latest FaceBook SDK for iOS, everything works fine except the first time I'm using the
[facebook dialog:#"feed" andParams:params andDelegate:self];
the dialog shows a empty canvas, and dismisses itself, the next time i try the same call the dialog is just fine.
So to reproduce this error, I'm deleting the app from Facebook to initiate the authorization, session, login etc.
Anyone else with the same problem?

I also face same issue like this. I have fix it by changing in FBDialog.m file
change
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
if (!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102)) {
[self dismissWithError:error animated:YES];
}
}
to
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
if (!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102)) {
// -999 == "Operation could not be completed"
if (!(([error.domain isEqualToString:#"NSURLErrorDomain"] && error.code == -999) ||
([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102))) {
[self dismissWithError:error animated:YES];
}
}
}
I hope this will solve your problem......

Related

GameCenter Operation cancelled if account never used with game center

I am using GameCenter on my app. I have these lines
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
}
the problem is that the localPlayer.isAuthenticated flag is always TRUE bur error variable comes with code 2 = "operation was cancelled" (???).
I have sign out from device's game center and from the store but this flag is always true and I do not see the game center sign in that my app should show when it starts. I don't see either the "welcome" banner that always show when a game that uses game center starts.
How do I force a sign out of game center to make the sign in window to show again?
I am compiling for iOS 4.3.
thanks
What I have discovered now is that this happens if you never signed in on device's game center. Once you login there, and say you want to use your username on game center, the app works. The worst part is this: suppose someone downloads the game but does not have the game center set yet. So, the game will never work for them? My game is supposed to work exclusively with game center on. So, for me this is an issue.
For me its working great. Just changed code from
if([GKLocalPlayer localPlayer].authenticated)
To
if([GKLocalPlayer localPlayer].authenticated == NO)
//Other codes
if([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
{
[self processGameCenterAuth: error];
}];
}
- (void) processGameCenterAuth: (NSError*) error
{
if(error == NULL)
{
[mGameCenterManager reloadHighScoresForCategory: self.currentLeaderBoard];
}
else
{
// NSLog(#"%#\n\n",[NSString stringWithFormat: #"Reason: %#", [error localizedDescription]]);
AppController *app = (AppController*)[UIApplication sharedApplication].delegate;
if(!app.isgameCenterStarted)
{
UIAlertView* alert= [[[UIAlertView alloc] initWithTitle:#"Game Center Unavailable" message: #"Player is not signed in"
delegate: NULL cancelButtonTitle: #"OK" otherButtonTitles: NULL] autorelease];
[alert show];
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"GameCenterUnAvailable" object:nil];
}
}
}

How to detect if a user says no to use my default location? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Determining if user has denied CoreLocation permission
How would I go about detecting if a user says no to "use my default location" in an iOS app?
I would like to present them with a different view controller depending on their choice.
thanks
For that, you need to implement below delegate method:
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
{
if([error code]== kCLErrorDenied)
self.locationDenied = YES;
switch ([error code]) {
// "Don't Allow" on two successive app launches is the same as saying "never allow". The user
// can reset this for all apps by going to Settings > General > Reset > Reset Location Warnings.
case kCLErrorDenied:
[appDelegate showAllowGPSLocationView];
default:
break;
}
self.locationDefined = NO;
}
You can create method "showAllowGPSLocationView" in AppDelegate. And show view to user that, you need to access GPS location.
Hope it will resolve your issue.
Happy Coding!
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusDenied) {
// denied
}
else if (status == kCLAuthorizationStatusAuthorized) {
// allowed
}
}
Implement CLLocationManagerDelegate delegate
For detailed explanation refer here.Worked for me.Hope it helps..
I made a function for that that solves the problem in two ways: first checks if location services are enabled (first location setting on device) and second checks if user authorized your app.
- (bool)locationAvailable
{
if (!([CLLocationManager locationServicesEnabled]) || ( [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied))
return FALSE;
else
return TRUE;
}
You can try like below:
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_2
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized))
#else
if ([CLLocationManager locationServicesEnabled])
#endif

Check for a valid Facebook Session

I was just checking for the state of FBSession
- (BOOL)hasValidSession {
return (self.session.state == FBSessionStateOpen)
}
Occasionally the state would briefly be changed to FBSessionStateOpenTokenExtended and this would return NO which would bring down my login modal. When I would click connect again it would crash the app for trying to reestablish an active facebook session. So I changed it to
- (BOOL)hasValidSession {
if (self.session.state == FBSessionStateOpen || self.session.state == FBSessionStateOpenTokenExtended) {
return YES;
}
else {
return NO;
}}
My above method works so far but it seems like a hack... What is the best ubiquitous way to check for a valid session in your app?
This is the way I check the facebook session in my app and it works for me:
-(BOOL)checkFacebookSession
{
if([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
{
NSLog(#"Logged in to Facebook");
[self openFacebookSession];
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc] initWithTitle:#"Facebook" message:#"You're already logged in to Facebook" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertDialog show];
[alertDialog release];
return YES;
}
else{
NSLog(#"Not logged in to Facebook");
return NO; //Show login flow.
}
}
Hope it helps! :D
The session is active if the state is either in FBSessionStateOpen or in FBSessionStateOpenTokenExtended. You can use the method below to get the current status of the user is logged in:
- (BOOL)isActiveSession
{
return (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended);
}

WebKitErrorFrameLoadInterruptedByPolicyChange what is that?

I get WebKitErrorFrameLoadInterruptedByPolicyChange in
(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
using FBDialog when trying to share an URL for the first time in
all next try are OK.
Do you have an idea why?
Thanks
Are you sure that you receive WebKitErrorFrameLoadInterruptedByPolicyChange?
There is a problem with SSO in Facebook connect. When an application become active after giving authorization in Safari or Facebook App, web view fails to load your initial share request.
I receive Error Domain=NSURLErrorDomain Code=-999. You can change if statement in (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error as follow to fix it:
if (!(([error.domain isEqualToString:#"NSURLErrorDomain"] && error.code == -999) ||
!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102))) {
[self dismissWithError:error animated:YES];
}
https://github.com/ShareKit/ShareKit/issues/56

How to handle app URLs in a UIWebView?

I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as this one and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown."
After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in -webView:shouldStartLoadWithRequest:navigationType:, but realized that there might be other kinds of app links that the system can handle. So I came up with this, instead:
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
// Give iOS a chance to open it.
NSURL *url = [NSURL URLWithString:[error.userInfo objectForKey:#"NSErrorFailingURLStringKey"]];
if ([error.domain isEqual:#"WebKitErrorDomain"]
&& error.code == 101
&& [[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication]openURL:url];
return;
}
// Normal error handling…
}
I have two questions about this:
Is this sane? I'm specifically checking for the error domain and error code and fetching the URL string from the userInfo. Is that stuff likely to remain?
This does work for the above-linked app store link, but when I switch back to my app, there appears to have been a subsequent failed request that failed with "Frame load interrupted". how can I get rid of that? It doesn't happen when I have the OS handle the request from -webView:shouldStartLoadWithRequest:navigationType:, so it's a bit annoying.
How do you handle such requests?
Here's what I came up with. In webView:shouldStartLoadWithRequest:navigationType:, I ask the OS to handle any non-http and non-https requests that it can, like so:
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Determine if we want the system to handle it.
NSURL *url = request.URL;
if (![url.scheme isEqual:#"http"] && ![url.scheme isEqual:#"https"]) {
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
return NO;
}
}
return YES;
}
This works very well except for the bloody "Frame Load Interrupted" error. I had thought that by returning false from webView:shouldStartLoadWithRequest:navigationType: that the web view would not load the request and therefore there would be no errors to handle. But even though I return NO above, I still "Frame Load Interrupted" error. Why is that?
Anyway, I'm assuming it can be ignored in -webView:didFailLoadWithError::
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
// Ignore NSURLErrorDomain error -999.
if (error.code == NSURLErrorCancelled) return;
// Ignore "Fame Load Interrupted" errors. Seen after app store links.
if (error.code == 102 && [error.domain isEqual:#"WebKitErrorDomain"]) return;
// Normal error handling…
}
And now iTunes URLs work properly, as do mailto:s and app links.
Starting with Theory's code, examine the URL for "itms" scheme(s) (this method can be called multiple times due to redirects). Once you see an "itms" scheme, stop the webView from loading and open the URL with Safari. My WebView happens to be in a NavigationController, so I pop out of that after opening Safari (less flashing).
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([[[request URL] scheme] isEqualToString:#"itms-apps"]) {
[webView stopLoading];
[[UIApplication sharedApplication] openURL:[request URL]];
[self.navigationController popViewControllerAnimated:YES];
return NO;
} else {
return YES;
}
}
Does it help if you register your app for handling itms: links?
e.g.
http://inchoo.net/iphone-development/launching-application-via-url-scheme/
You may start with scheme http but then get an itms redirect, which could fail if your app is not registered as handling that scheme.