I have implemented facebook api in my app to support facebook login. When I tap the facebook button then it launches a safari it does not redirect to my native facebook app. I have installed facebook app & logged in.
I have used following code
// Do any additional setup after
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.delegate=self;
loginButton.readPermissions =
#[#"email", #"user_friends"];
[self.view addSubview:loginButton];
How can I launch the fb native app?
EDIT:
AppDelegate code
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
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
];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[FBSDKAppEvents activateApp];
// 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.
}
#end
Maybe you are missing this in your appdelegate.m ?
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Related
I need to add DeepLinking to my React Native app, and as mentioned in docs I need to add the method above #and.
// Add this above `#end`:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
I've added this method, but I also have similar one for Twitter login. Here's my AppDelegate.m:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
return [[Twitter sharedInstance] application:app openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
#end
I get an error:
Duplicate declaration of method 'application:openURL:options:'
How can it be solved? I'm not an iOS developer, so it's hard to figure out, but I think both two methods should be somehow combined.
As the error suggests, you can not have multiple functions with the same signature.
A simple solution here is merging your implementation into one, like this:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
return ([[Twitter sharedInstance] application:app openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]);
}
After Xcode update to 8
my [FBSDKAccessToken currentAccessToken] didn't work.
I try update FacebookSDK but not working.
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
[Fabric with:#[[Crashlytics class]]];
[FIRApp configure];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
[Fabric with:#[[Crashlytics class]]];
[FIRApp configure];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
MainViewController.m
-(void)viewWillAppear:(BOOL)animated{
if ([FBSDKAccessToken currentAccessToken]){
[self loadFromCoreData];
}
}
I have to integrate the latest FB-SDK into my iOS app - and the nightmare starts with the app delegate.
The docs say to implement this in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
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
];
}
But my app isn't for FB only, it does Dropbox and YouTube uploads as well.
So my application:openURL: method looks like this now:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
// Facebook
if([FBSession.activeSession handleOpenURL:url]){
BOOL result = [FBSession.activeSession handleOpenURL:url];
return result;
}
// Dropbox
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(#"App linked successfully!");
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
FBSession doesn't exist anmyore, though. So how do I tell the openURL: calls from Facebook and Dropbox apart?
I have implemented Facebook SDK in my iOS app following the Facebook guidelines and in my AppDelegate I set:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// more code
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
}
Now, I have also implemented handoff in my app and - (BOOL) application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType will never be called when app starts from scratch because FBSDKApplicationDelegate sharedInstance returns false.
So my question: Is there any side effects if I don't return the result of [FBSDKApplicationDelegate sharedInstance]application:didFinishLaunchingWithOptions and I return my custom result? For example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// more code
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
Short answer NO.
[FBSDKApplicationDelegate application: didFinishLaunchingWithOptions:]
method should be invoked just for the proper use of the Facebook SDK from the
[UIApplicationDelegate application:didFinishLaunchingWithOptions:] method
of the AppDelegate for your app.
This method return YES if the url was intended for the Facebook SDK, NO if not.
In latest Facebook getting started docs they mention it
To post process the results from Facebook Login or Facebook Dialogs (or any action that requires switching over to the native Facebook app or Safari) you need to conenct your AppDelegate to the FBSDKApplicationDelegate. In your AppDelegate.m add:
// AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}
I'm trying to integrate Facebook to my Parse project, but I have problems with the new SDK version.
With the older versions I've just imported the related header files into my AppDelegate, pasted two methods and it worked well.
This is how I've done it:
// AppDelegate.m
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FacebookSDK/FacebookSDK.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Parse setApplicationId:#"xy"
clientKey:#"xy"];
[PFFacebookUtils initializeFacebook];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
return YES;
}
- (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]];
}
But now the Facebook SDK contains several frameworks and it's not so clear which one is needed or not. Actually I'm trying the below code, but getting this error: Use of undeclared identifier 'PFFacebookUtils'.
// AppDelegate.m
#import <Parse/Parse.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Parse setApplicationId:#"xy"
clientKey:#"xy"];
[PFFacebookUtils initializeFacebook];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
I would really appreciate if somebody could show me his own Fb sdk setup in the AppDelegate with Parse or explain me what did I wrong.
Here I share how I've integrated FB to my project with Parse.
AppDelegate.m
#import <ParseFacebookUtils/PFFacebookUtils.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[PFFacebookUtils initializeFacebook]; // don't forget this. it's not mentioned in tutorial
...
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
}
- (void)applicationWillTerminate:(UIApplication *)application {
[[PFFacebookUtils session] close];
}
Hope this helps.