Connecting Parse with FB integration - ios

I'm creating a chat app, and the user is first taken to the main menu, where they can select "chat" and then be directed to a FB Login feature, after the user logs in with FB, they are supposed to be redirected to a tab bar controller. However I cannot figure out how to set the programatic segue up so that it takes the user directly to that screen after a successful login.
I don't know if that's why Parse isn't collecting the User Data or not, but I get this warning when running the app: [10799:60b] Warning: A long-running Parse operation is being executed on the main thread. Break on warnParseOperationOnMainThread() to debug. My question is how do I create that segue to my Tab Bar Controller and am I missing something with Parse?
Here is my AppDelegate.m file:
#import "CCAppDelegate.h"
#import <Parse/Parse.h>
#implementation CCAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[Parse setApplicationId:#"XXXX"
clientKey:#"XXXX"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[PFFacebookUtils initializeFacebook];
[FBLoginView class];
[FBProfilePictureView class];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
return wasHandled;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
And here is my CCLoginViewController.m file:
#import "CCLoginViewController.h"
#interface CCLoginViewController ()
#property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
#end
#implementation CCLoginViewController
-(void)toggleHiddenState:(BOOL)shouldHide
{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePictureView.hidden = shouldHide;
}
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = #"You are logged in.";
[self toggleHiddenState:NO];
}
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
NSLog(#"%#", user);
self.profilePictureView.profileID = user.objectID;
self.lblUsername.text = user.name;
self.lblEmail.text = [user objectForKey:#"email"];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = #"You are logged out";
[self toggleHiddenState:YES];
}
-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(#"%#", [error localizedDescription]);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.loginView.delegate = self;
[super viewDidLoad];
// Do any additional setup after loading the view.
[self toggleHiddenState:YES];
self.lblLoginStatus.text = #"";
self.lblLoginStatus.text = #"";
self.loginView.readPermissions = #[#"public_profile", #"email"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end

According to the docs on iOS, Facebook Users you should be calling FBAppCall slightly differently:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
The key part you're missing is the withSession:[PFFacebookUtils session], which I'm guessing lets Parse know about what Facebook is doing.
I also don't see any Parse query in your code, so some other part of your code must be triggering that warning, somewhere you're doing a query without using a withBlock:, which lets it handle the results on a background thread without locking up the UI.

Related

Loading view after login with Facebook in iOS app

I'm beginner in iOS programming. I created an application which on the beginning user is logging-in with Facebook. After login, the app should display a second view where are information fetched from facebook: profile picture, age, name, etc.
But my is problem because after successfully logged I see the blanks: UIImageView is empty, which should have a profile picture, empty UITextField, which should have the name and age and non active UISegmentControl, which should indicate gender. In contrast view of all these data it appears only when I want to log off as a user of Facebook and I get alert asking if you really want to log out. At this point, in the background, I can see the view from all the data from Facebook. What is wrong? Any sugestions?
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
//loginButton.center = self.view.center;
[self.view addSubview:loginButton];
if ([FBSDKAccessToken currentAccessToken]) {
// User is logged in, do work such as go to next view controller.
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
App.Delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[FBSDKLoginButton class];
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url sourceApplication:sourceApplication annotation:annotation];
}

Facebook SDK loginViewShowingLoggedInUser not getting called

I'm new to iOS and trying to implement Facebook login and after login is successful I want it to go to another view. I've done everything that the documentation shows but I can't get the delegate to be called. I have seen people questions but I tried all of them. Nothing worked not sure if I miss something obvious.
This is my LoginViewController.h
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#interface LoginViewController : UIViewController <FBLoginViewDelegate>
#end
This is my LoginViewController.m file
#import "LoginViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"Starting");
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate = self;
return YES;
}
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
NSLog(#"You're logged in");
[self performSegueWithIdentifier:#"segueToAnotherView" sender:self];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)logoutView {
NSLog(#"Logged out");
}
#end
I also have this in my AppDelegate.m
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
When the app comes back I don't see the log "You're logged in" or even "Logged out" at all. I can only see the Logout button from Facebook. Also, the two view controllers are connected by a segue.
You are going to want to add your app to Facebook, Download the Facebook SDK and add some values to your plist. There is a lot more you're going to need to do here and I suggest you read Facebook SDK Documentation If you need more help, I am brand new to iOS as well and just implemented my own Facebook login (I guess you could call it custom) and it works smoothly.
Checkout the following code to log in from facebook
#define PERMISSION #"publish_actions",#"email",#"public_profile"
#property (strong, nonatomic) FBSession *session;
NSArray *permissions = [[NSArray alloc] initWithObjects:PERMISSION,nil];
self.session = [[FBSession alloc] initWithPermissions:permissions];
[FBSession setActiveSession:self.session];
// if the session isn't open, let's open it now and present the login UX to the user
[self.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (!error) {
//Handle code for success
} else {
//Code for failure
}
}];

google plus login is redirecting to google.com in ios

I followed google developer docs to implement a simple google plus (gmail) sign in button in my basic app. But When i run the code it going to google.com.
So here are the steps i followed.
1.Created new client id and added that into app from google console.
2.Imported frameworks
3.When i run the code i can see
it first open google sign in page then it will open Oauth page if i press "allow" access then it will redirect from "accounts.google.com" to "google.com.
I have created a sample project for that
Here is my code and screen shots
my file and framework list
CODE
AppDelegate.m
#import <GooglePlus/GooglePlus.h>
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
ViewController.h
#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>
#class GPPSignInButton;
#interface ViewController : UIViewController<GPPSignInDelegate>
#property (strong, nonatomic) IBOutlet GPPSignInButton *signInButton;
#end
ViewController.m
//
#import <GooglePlus/GooglePlus.h>
#import "ViewController.h"
#import <GoogleOpenSource/GoogleOpenSource.h>
#define kClientId #"49781846815-pbsb1vso4nrbes9a4al5kae2d98ie3cf.apps.googleusercontent.com"
#define kGTLAuthScopePlusLogin #"https://www.googleapis.com/auth/plus.login"
#interface ViewController ()
#end
#implementation ViewController
#synthesize signInButton;
- (void)viewDidLoad {
[super viewDidLoad];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
// Do any additional setup after loading the view, typically from a nib.
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
signIn.scopes = #[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
signIn.scopes = #[ #"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(#"Received error %# and auth object %#",error, auth);
if (error) {
// Do some error handling here.
} else {
[self refreshInterfaceBasedOnSignIn];
}
}
-(void)refreshInterfaceBasedOnSignIn {
if ([[GPPSignIn sharedInstance] authentication]) {
// The user is signed in.
NSLog(#"hi");
self.signInButton.hidden = YES;
// Perform other actions here, such as showing a sign-out button
} else {
self.signInButton.hidden = NO;
// Perform other actions here
}
}
- (void)presentSignInViewController:(UIViewController *)viewController {
// This is an example of how you can implement it if your app is navigation-based.
[[self navigationController] pushViewController:viewController animated:YES];
}
#end
Please help to clear this google.com redirect issue and also to develop a good login.
As of May 2015, even if you got this working, your app would then be rejected by Apple's App Store review team because of a childish fight going on between Apple and Google. See this issue in the Google+ SDK: https://code.google.com/p/google-plus-platform/issues/detail?id=900

Check application lifecycle's status

#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
I want to check when this all method calls.
How can I put NSLog to every method so whenever it gets called I know?
copy & paste ?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"didFinishLaunchingWithOptions");
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(#"applicationWillResignActive");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(#"applicationDidEnterBackground");
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"applicationWillEnterForeground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(#"applicationDidBecomeActive");
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(#"applicationWillTerminate");
}
#end

Facebook login for iOS doesnt work

I'm trying to integrate a Facebook login into my app, and been doing so for the past two days without luck.
The login-button works: It logs me in and then changes text to "log out".
However, nothing else works. I can't get the name, I've tried placing random NSLog statements around in my code, but the only ones that prints are the ones in viewDidLoad. Nothing else.
Here's my code (I'm using a graphical implementation of the button btw)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"Print 1");
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"Print 2");
// Override point for customization after application launch.
[FBLoginView class];
self.loginView.readPermissions = #[#"basic_info", #"email", #"user_likes"];
NSLog(#"Initiating the FBLoginView");
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(#"Print 3");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSLog(#"Print 4");
}
return self;
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {
NSLog(#"Print 5");
}
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
NSLog(#"Print 6");
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"Print 7");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
I'm very unsure as to where I'm gonna place the readPermissions, but I've tried nearly everything. I've also tried different stuff like
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.readPermissions = #[#"basic_info", #"email", #"user_likes"];
etc, but nothing works. Right now I have connected the loginView to my .h file via an IBOutlet, not sure if that's how it's done though. Facebooks guide online is really bad at this...
Can anyone help me? Why doesn't any of my NSLog statements print anything except the one in viewDidLoad?
You are forgetting to assign the delegate property of the login method. You need
self.loginView.delegate = self;
or else the delegate methods will never be called

Resources