This is to try and get both frameworks to load the URL Schemes from my .plist file in my iOS app. Currently the .plist is formatted as such:
URL Types (array) >
Item 0 (dictionary) >
URL Schemes (array) >
item 0 (string) - fbfacebookappkey
item 1 (string) - db-dropboxappkey
Is this correct firstly?
Here is my appdelegate code that is failing:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
//Facebook specific code
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
//Dropbox specific code
DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
if (account)
{
DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
[DBFilesystem setSharedFilesystem:filesystem];
return YES;
}
else
return NO;
}
Thanks in advance!
Change your app delegate code to the following:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
//Facebook specific code
if( [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]])
return YES;
//Dropbox specific code
DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
if (account)
{
DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
[DBFilesystem setSharedFilesystem:filesystem];
return YES;
}
else
return NO;
}
Otherwise only Facebook url will work.
Related
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;
}
I'm trying to handle both of Twitter and deep link in openURL, using ReactNative.
The code below does not work, ending up go into if (LinkingHandled) even when handling Twitter.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
bool TwitterHandled = [[Twitter sharedInstance] application:application openURL:url options:options];
bool LinkingHandled =[RCTLinkingManager application:application openURL:url options:options];
if (TwitterHandled) {
return TwitterHandled;
}
if (LinkingHandled) {
return LinkingHandled;
}
return NO;
}
What is wrong with this? I'm new to ObjC.
Use } else if { so only Twitter goes if it gets handled, and 'linking' will only go if TwitterHandled is NO and LinkingHandled is YES.
This can be simplified into one expression:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
return [Twitter.sharedInstance
application:application
openURL:url options:options] ||
[RCTLinkingManager
application:application
openURL:url
options:options];
}
Switch to Swift if you can. 🙂
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?
This question already has answers here:
FBSDKShareDialog cancels when it should post
(4 answers)
Closed 7 years ago.
I'm trying to share a post with the Facebook SDK, but sharerDidCancel is always called, either if I share or cancel the post.
Here is my code
- (void)shareFacebook {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.google.com"];
[FBSDKShareDialog showFromViewController:view
withContent:content
delegate:self];
}
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary*)results {
NSLog(#"FB: SHARE RESULTS=%#\n",[results debugDescription]);
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(#"FB: ERROR=%#\n",[error debugDescription]);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(#"FB: CANCELED SHARER=%#\n",[sharer debugDescription]);
}
This class implements the FBSDKSharingDelegate, in my Info.plist I already entered the FacebookAppID and FacebookDisplayName.
In my AppDelegate I have this method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
What I'm doing wrong? I exactly followed the Facebook SDK guide.
Thanks
Solved, my error was in the AppDelegate method:
here is a link with the solution http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html
And here is the 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];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [ [FBSDKApplicationDelegate sharedInstance] application :application
didFinishLaunchingWithOptions:launchOptions]
}
i'm getting problem with the function in AppDelegate
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
A lot of libraries must put some return code in this function for their configurations. Like this:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
//facebook
//attempt to extract a token from the url
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(#"In fallback handler");
}];
//library
BOOL urlHasBeenHandledByDispatcher = [[GRKConnectorsDispatcher sharedInstance] dispatchURLToConnectingServiceConnector:url];
if ( urlHasBeenHandledByDispatcher ) return YES;
return NO;
//facebookSession
return [FBSession.activeSession handleOpenURL:url];
}
How can I config in this situation to make all the library working?
You should change your code and return value only once. Try following code:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
//facebook
//attempt to extract a token from the url
BOOL result = NO;
result |= [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(#"In fallback handler");
}];
//library
result |= [[GRKConnectorsDispatcher sharedInstance] dispatchURLToConnectingServiceConnector:url];
//facebookSession
result |= [FBSession.activeSession handleOpenURL:url];
return result;
}
This method will return YES if at least one library returns YES, and NO otherwise.