Facebook SDK, Login Error - objective-c

I'm setting up my app so that users can login with Facebook. I've loaded the Facebook SDK, but for some reason I get this error in the console when I try to "log in" to Facebook:
FBSDKLog: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x10906da90 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ErrorSessionKey=, expirationDate: 2014-01-02 03:26:48 +0000, refreshDate: 2013-11-03 06:19:26 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions.
Does anyone know why? Take a look at the code below. I feel like it has something to do with my ShowLoginView method (I'm attempting to open the SSLoginViewcontroller Xib on top of an existing Storyboard). I was able to log into Facebook fine before I started messing with this method... Help :)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.mainViewController = [[SSViewController alloc]
initWithNibName:#"SSViewController" bundle:nil];
self.navController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// Yes, so just open the session (this won't display any UX).
[self openSession];
} else {
// No, display the login page.
[self showLoginView];
}
return YES;
}
- (void)showLoginView
{
UIViewController *topViewController = [self.navController topViewController];
UIViewController *modalViewController = [topViewController modalViewController];
// If the login screen is not already displayed, display it. If the login screen is
// displayed, then getting back here means the login in progress did not successfully
// complete. In that case, notify the login view so it can update its UI appropriately.
if (![modalViewController isKindOfClass:[SSLoginViewController class]]) {
SSLoginViewController* loginViewController = [[SSLoginViewController alloc]
initWithNibName:#"SSLoginViewController"
bundle:nil];
[topViewController presentViewController:loginViewController animated:NO completion:nil];
} else {
SSLoginViewController* loginViewController =
(SSLoginViewController*)modalViewController;
[loginViewController loginFailed];
}
}

Related

Game center unavailable (player is not signed in )

I am integrating game center on cocos2d project.
GKLeaderboardViewController* leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil){
NSLog(#"view make");
leaderboardController.leaderboardDelegate = self;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.category = #"myGameBoard";
[[CCDirector sharedDirector] presentViewController: leaderboardController animated: YES completion:nil];
show popup
Game Center unavailable
Player is not signed in
and no leaderboard appeared.
My Conditions are
1)testuser looks successfully loginnd
this message appeared on screen.
Welcome back testuser
*** sandbox ***
2)then this message appeared
Game Center unavailable
Player is not signed in
3)App upload is ready and pass the validate on organizer
4)app version on itunes connect and local is the same 1.00
5)Bundle Idenfier on itunes connect and local is the same
6)leaderboardController.category name 'myGameBoard' is correctly set.
is there any other point I need to investigate??
I solved this problem for TEST MODE in this way:
Go to Game Center App
Tab Friends
Click Setting
at the end of the screen: SANDBOX and LOGGING MUST BE ON MODE
I hope that it works for everyone
I solved this issue by ensuring the local user was authenticated and logged in:
- (void) authenticateLocalUser
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (![localPlayer isAuthenticated])
{
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error && viewcontroller)
{
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
UIViewController *currentViewController = [[appDelegate window] rootViewController];
[currentViewController presentViewController:viewcontroller animated:YES completion:nil];
}
})];
}
}

UIActivity custom activityViewController crash on iPad

I have a custom UIActivity that I use in order to create a Contact to the device's AddressBook. In this UIActivity, I create an ABNewPersonViewController, put it inside a UINavigationController and return it in UIActivity's
- (UIViewController *)activityViewController
The problem is that on the iPad I get a crash due to a reference to a released UINavigationController. Messages are of type:
*** -[UINavigationController _viewControllerForSupportedInterfaceOrientations]: message sent to deallocated instance 0xa6f1660
Also after my controller is dismissed, the iPad does not autorotate the view when the interface changes orientation.
The code I use is the following:
In UIActivity
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
// Prepare the AB View Controller
ABRecordRef aContact = ABPersonCreate();
CFErrorRef error = NULL;
ABRecordSetValue(aContact, kABPersonKindProperty, kABPersonKindOrganization, &error);
ABRecordSetValue(aContact, kABPersonOrganizationProperty, #"Apple Inc.", &error);
ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phone, #"+1 2345 784513", kABWorkLabel, NULL);
ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &error);
CFRelease(phone);
self.newContactVC.title = #"New company";
self.newContactVC.displayedPerson = aContact;
[self.navigation setViewControllers:[NSArray arrayWithObject:self.newContactVC]];
CFRelease(aContact);
}
- (UIViewController *)activityViewController
{
return self.navigation;
}
// Dismisses the new-person view controller.
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
{
[self activityDidFinish:YES];
}
In the ViewController that calls this UIActivity
- (IBAction)showActionsSheet:(id)sender {
AddToAddressBookActivity *abActivity = [[AddToAddressBookActivity alloc] init];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:nil
applicationActivities:[NSArray arrayWithObject:abActivity]];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
if (!self.popover || ![self.popover isPopoverVisible]) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[self.popover setDelegate:self];
self.popover.passthroughViews = nil;
[self.popover presentPopoverFromRect:self.showASBtn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
Any help would be greatly appreciated.
Link to a demo project:
http://ge.tt/23MeOYq/v/0?c
I had a similar problem, except the crash occurred on rotation after the activity view controller was dismissed. In my case, I had the custom view controller in a storyboard setup to present as "fullscreen", and on changing it to display as "form sheet" the crash went away. I don't know why that made a difference though.
Regarding your autorotation not working after the custom view controller dismisses, try adding a completion handler to your activity view controller to nil your popover view controller ivar. I noticed that if I didn't do this the custom activity and the custom view controller don't get dealloc'd, and autorotation doesn't happen. e.g.:
avc.completionHandler = ^(NSString* activityType, BOOL completed){
if ( UIUserInterfaceIdiomPad == [UIDevice currentDevice].userInterfaceIdiom )
self.popover = nil;
};
Also, check out the post at: "activityviewcontroller not dismissing", which I found helpful.

self.navigationController == nil after awaking from LocalNotification

I'm working in Xcode 4.3.2
I implemented Local Notifications that alert the user of a new event at a predetermined time. So when my app is in the background and the clock strikes 8 am (for instance), the user will get a notification from my app.
When the user decides to view the app from the background I load a nib. Currently, this nib works properly: it shows the view as it was it arranged in the nib. However, after the nib is shown to the user, I want to forward the user to a different view in the LocalNotificationsHandler.m. When I attempt to push the second view, my app fails. So while there isn't an error message, it seems the second nib will not load.
In short the flow goes as follows:
user gets notification while my app is running in the background
user chooses to view the app
the LocalNotificationsHandler nib will load
self.navigationController == nil (in LocalNotificationsHandler.m)
self.navigationController will not "[pushViewController: "new view" animated:YES]" to get a new view
I'm wondering if there is something I'm missing from my AppDelegate.m file so I've included
"didFinishLaunchingWithOptions" from my AppDelegate.m file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
NSLog(#"did finish launching with options");
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
if (self.locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
locationManager.purpose = #"We will try to use you location";
}
if([CLLocationManager locationServicesEnabled])
{
[self.locationManager startUpdatingLocation];
}
self.navigationController.navigationBar.tintColor = nil;
return YES;
}
You are using the outdated (since iOS 3) method of adding the viewcontroller's view to the main UIWindow. That should be looking like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// create properly sized window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create instance of root VC and assign to window
MainViewController *vc = [[MainViewController alloc] init];
self.window.rootViewController = vc;
[vc release];
[self.window makeKeyAndVisible];
return YES;
}
The navigationController property of a view controller is ONLY set if it is actually presented from a UINavigationController.
See this writeup for more information: http://www.cocoanetics.com/2012/11/revisited/

Showing Viewcontrollers modally in a delege functions

I have some code that shows two UIViewController in a delegate.
RootViewController.m
request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:#"***some https url here ***"]];
// custom implementation of NSURLConnectionDelegate
dataman = [[DataManager alloc] initWithParentcontroller:self];
mainConn = [[NSURLConnection alloc] initWithRequest:request delegate:dataman];
In AuthenticationViewController.h
#protocol ShowAuthenticationWindowDelegate <NSObject>
#required
- (void) onFinishedEnteringCredentials:(NSURLCredential*)credentials;
- (void) onCancelAuthentication;
#end
in AuthenticationViewController.m
- (IBAction) onClickLogin:(id)sender;
{
....
// authDelegate => id <ShowAuthenticationWindowDelegate>
[authDelegate onFinishedEnteringCredentials:credentials];
[self dismissModalViewControllerAnimated:YES];
....
}
in DataManger.h (DataManager class) implements the NSURLConnectionDelegate and ShowAuthenticationWindowDelegate.
In Datamanager.m
In the didReceiveAuthenticationChallenge delegate function I show the AuthentiationViewController as a modal dialog to gather username/password.
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
AuthenticationViewController *authview = [[AuthenticationViewController alloc] initWithNibName:#"AuthenticationViewController" bundle:[NSBundle mainBundle]];
authview.modalPresentationStyle = UIModalPresentationFullScreen;
authview.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
authview.credentialsDelegate = self;
[rootController presentModalViewController:authview animated:YES];
}
Here I show a UIViewController which is an activity indicator in a view. I am showing it modally after I dismiss the previous AuthenticationViewController dialog in one of the login button event handler by called dismissModalViewController. After sending the credentials with challenge object (previously cached) I am showing the ActivityViewController modally, but it is not shown no matter what I do. I tried to show an UIAlertView which works, but my activityviewcontroller is not shown. I checked the parameters and objects everything is valid. even the delegate wire ups!!! All the code is getting called but the dialog is not shown.
May be I am missing something ???
- (void) onFinishedEnteringCredentials:(NSURLCredential*)credentials;
{
[[authChallenge sender] useCredential:credentials forAuthenticationChallenge:authChallenge];
// create an activity modal dialog
if (activityController == nil) {
activityController = [[ActivityViewController alloc] initWithNibName:#"ActivityViewController" bundle:[NSBundle mainBundle]];
activityController.modalPresentationStyle = UIModalPresentationFullScreen;
activityController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
[rootController presentModalViewController:activityController animated:YES];
}
I have figure out the solution, if anyone want to show two modal dialogs back to back, you should set the "animated" parameter to "NO" on the controller that is being dismissed. It seems like the animation transition is not being completed by the time the next controller is shown with "presentViewController" function.

Proper view controller not displayed when tapping push notification

I have implemented push notifications and am attempting to take the user to another view controller (opposed to just opening the app) when they tap the notification. I was going off of the apple website example but have not had any luck yet.
It seems that it never even enters my code as it should. I tried putting an NSLog to prove that and I was right.
Does anyone know why? The view controller I want implemented is called statsViewController.
Thanks
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif) {
NSLog (#"We are here now");
[self handleRemoteNotification:application userInfo:remoteNotif]; //custom method where View controller will be implemented
return YES;
}
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
-(void) handleRemoteNotification:(UIApplication *)application userInfo:(NSDictionary *)userInfo {
application.applicationIconBadgeNumber = 0;
statsViewController* viewController = [[statsViewController alloc] init];
[navController pushViewController:viewController animated:YES]; //Don't think this is right since I never use it in didFinishLaunching... I simply just declared it delegate.h
[viewController release];
}