Getting an error in FBSDKApplicationDelegate class - ios

I'm getting an error when I build my xCode 7.3.1 project.
/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.h:77:35: No type or protocol named 'UIApplicationOpenURLOptionsKey'
Problem func like this:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
Need your help! Thx..

The Latest FBSDKCoreKit does'nt work with Xcode 7.3. You should use XCode 8 or older versions of Facebook framework.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
has been replaced in XCode 8 as
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
Try this facebook SDK instead
https://origincache.facebook.com/developers/resources/?id=FacebookSDKs-iOS-4.14.0.zip
For more information on changes from iOS 9 to 10 , go to this link https://developer.apple.com/library/content/releasenotes/General/iOS10APIDiffs/Objective-C/UIKit.html

Instead of this code :
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
Use this code :
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}

Try this code:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options];
}

Related

No known class method for selector 'application:openURL:options:sourceApplication:annotation'

I am integrating Fitbit into my react-native app and there is a piece of code that I should add to my AppDelegate.m:
#import "RCTLinkingManager.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [RCTLinkingManager
application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
but I already have that set up that handles FB login and firebase linking and maybe something else:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
return YES;
}
if ([RCTLinkingManager application:app openURL:url options:options]) {
return YES;
}
return NO;
}
and when I'm trying to combine them into that:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation{
if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options ]) {
return YES;
}
if ([RCTLinkingManager application:app
openURL:URL
options:options
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation ]) {
return YES;
}
return NO;
}
I'm getting the error: No known class method for selector 'application:openURL:options:sourceApplication:annotation'
Is it mean that sourceApplication and annotation are already included into options?
Any help welcome
you should call the FBSDKApplicationDelegate differently:
if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
return YES;
}

iOS AppDelegate.m: Handling openUrl RCTLinkingManager and Twitter - Duplicate declaration of method 'application:openURL:options:'

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]);
}

iOS: objective-C, facebook and twitter implementation

How do you combine these 2 functions?
If i run it like this, I get this on Xcode error: duplicate declaration of method 'application:openURL:options:'. The idea is to implement facebook and twitter login buttons.
// Twitter
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<NSString *,id> *)options {
return [[Twitter sharedInstance] application:app openURL:Url options:options];
}
// Facebook
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handledByFacebook = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
BOOL handledByTwitter = [[Twitter sharedInstance] application:application
openURL:url
options:options];
return handledByFacebook || handledByTwitter;
}

Two packages conflict in AppDelegate.m file

I use https://github.com/devfd/react-native-google-signin and https://github.com/luisfcofv/react-native-deep-linking packages in my project. I did not solve the following part of the AppDelegate.m file so that the packages can work.
For this react-native-google-signin
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RNGoogleSignin application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
For this react-native-deep-linking
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
I'm not good at Objective-C. How do I return RNGoogleSignin and RCTLinkingManager with a single function?
Since both methods return a BOOL, you could try something like this:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL success = [RNGoogleSignin application:application openURL:url
sourceApplication:sourceApplication annotation:annotation])
if (!success)
success = [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
return success;
}
updated based on comments from #rmaddy.

How to setup Facebook iOS SDK properly with Parse in AppDelegate?

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.

Resources