Facebook API permissions in iOS - ios

I'm working on an app that uses the Facebook SDK. Until now I've not had any significant problems. I've been using the API to request a user's photos. However, after deleting the app on the device to try out some log-in scenarios, the app now only requests the public profile.
This is the call being made
self.loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
but this is what shows on the device
When I request the user's photos the data is empty (as you'd expect with just the public profile).
What did I do to break it? And more importantly, how do I fix it?
EDIT: I've created a new app on the Facebook developer portal and I get exactly the same results.

For reasons I can't establish, this error was somehow connected to the way that the FBLogin was initialising.
In my app I had created an FBLoginView in the storyboard and I was doing the alloc/init in the viewDidLoad method of the view controller handling my Facebook information.
I had checked to ensure that the FBLoginView class was associated with the view in the storyboard and that the FBLoginView class was declared in my app delegate.
However, I was seeing the problem as stated. It was only when I removed the FBLoginView from the storyboard and created it programmatically (as in the FBLoginUIControlSample that's available on Facebook) that the problem was resolved.
For reference, this DID NOT work for me
-(void)viewDidLoad{
[super viewDidLoad];
self.loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
self.loginView.delegate = self;
}
This DID work.
-(void)viewDidLoad{
[super viewDidLoad];
FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
loginView.delegate = self;
loginView.frame = CGRectOffset(loginView.frame,
(self.view.center.x - (loginView.frame.size.width / 2)),
5);
loginView.center = self.view.center;
[self.View addSubview:loginView];
}

Related

Facebook login is redirecting to logout page

I have set up a Facebook login for my app and it works but what I don't know how to do is when you log in the app through Facebook, the app should take you to a menu screen that I have created in a view controller. Right now with Facebook login it is taking me to the log out page. Any help would be appreciated.
In my ViewController:-
- (void)viewDidLoad{
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.readPermissions = # [#"public_profile", #"email", #"user_friends"];
[self.view addSubview:loginButton];
if ([FBSDKAccessToken currentAccessToken]) {
[self performSegueWithIdentifier:#"Cell" sender:self];
}
}
I am checking if the user is logged in, and if yes perform the segue nothing happens.
When your facebook request complete the authentication process, the FB button is automatically turned into "log-out" mode since that is the next option for the user. To transition to a new view controller you can call a segue in the delegate method as shown below. This method will be called at the end of the FB credentialing, if you have subscribed to the delegate FBSDKLoginButtonDelegate:
- (void)loginButton:(FBSDKLoginButton*)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult*)result
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
}

FBSDKLoginButton with native iOS dialog

I have my login button setup like this.
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
loginButton.loginBehavior = 0; // native
[self.view addSubview:loginButton];
What I wish to have is a native login dialog instead of the web view one, so I assign the loginBehavior to 0, as specified in this enum
typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior) {
FBSDKLoginBehaviorNative = 0,
FBSDKLoginBehaviorBrowser,
FBSDKLoginBehaviorSystemAccount,
FBSDKLoginBehaviorWeb,
};
However, no matter what behavior I set, I only get web view login.
I am running my app in a real iOS device, with Facebook app installed and authenticated.
I notice apps such as Tinder, or Instagram have their own native login dialogs. Is this a misconfiguration from my part?

adViewWillDismissScreen in GADBannerViewDelegate is not called

I created GADBannerView and register the view controller as GADBannerViewDelegate.
However I cannot make these two methods (adViewWillDismissScreen and adViewDidDismissScreen) call. Only adViewWillPresentScreen is called
I've followed the url http://googleadsdeveloper.blogspot.com/2014/05/google-mobile-ads-sdk-note-on-ad-click.html
on both Simulator and iOS device. The two methods still not get called.
The below is my code.
self.mBannerView1 = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:CGPointMake(0, 100)];
self.mBannerView1.adUnitID = kMyAdUnitID;
self.mBannerView1.rootViewController = self;
self.mBannerView1.delegate = self;
[self.mBannerView1 loadRequest:request];
[self.view addSubview:self.mBannerView1];

Admob showing ads in simulator but not in device

This is the code that I am currently using to show some ads on my device. But it doesn't seem to work as of now. Need some guidance on what could be going wrong here.
self.adBanner = [[GADBannerView alloc]
initWithFrame:CGRectMake(0,468,320,50)];
self.adBanner.adUnitID = #"a153b29f919d822";
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
//self.adBanner.center = CGPointMake(self.view.center.x, self.adBanner.center.y);
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[self.adBanner loadRequest:r];
Thanks.
If you have recently setup up your account in Google AdMob, it is going to take sometime for the ads to start appearing on the device.
But you can try setting testDevices in your GADRequest. The device Id will be being printed out in your console by the AdMob SDK.
Then add the below code.
r.testDevices = #["test_device_id"];

Sharing photos on facebook from iOS application without facebook app

Is it possible on iOS < 6?
In iOS 6+, I can share using message composer.
What about previous version of iOS? FB SDK share uses facebook app id so it's not the way.
Maybe i can open native facebook app with scheme like fb://share/photo/[image_data]?
Any other ideas?
For iOS < 6, you can always used ShareKit plugin.
In this repository, they share nice example to share image on your fb account.
Have a look at the class ExampleShareImage:
- (void)loadView
{
[super loadView];
self.imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sanFran.jpg"]] autorelease];
imageView.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
[self.view addSubview:imageView];
}
- (void)share
{
SHKItem *item = [SHKItem image:imageView.image title:#"San Francisco"];
/* optional examples
item.tags = [NSArray arrayWithObjects:#"bay bridge", #"architecture", #"california", nil];
//give a source rect in the coords of the view set with setRootViewController:
item.popOverSourceRect = [self.navigationController.toolbar convertRect:self.navigationController.toolbar.bounds toView:self.view];
*/
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[SHK setRootViewController:self];
[actionSheet showFromToolbar:self.navigationController.toolbar];
}
You can also integrate FBConnect framework provide by Facebook.

Resources