In react native the iOS Universal links are working perfectly when the app is in kill/quiet state I tested it with safari but when the app is in background state it only opens the app not working in background state my listener is not working.
Linking.addEventListener('url', async (link) => {
console.log('Linking-addEventListener-link', link);
})
Please check this method is added or not into AppDelegate.m file.
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^) (NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
For everyone having the same issue, just make sure that
#import <React/RCTLinkingManager.h> is just at the top of the imports, do not add it inside any #if #endif import condition.
also add
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
just before the last #end inside the #implementation AppDelegate, hope it might help someone.
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]);
}
I am currently handling ios universal links through the RCTLinking API. For some reasons, I need to work with Firebase dynamic links and I am wondering if it is possible to use both in my app.
My issue is that the implementation in :
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
and
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
that seems incompatible as I would need to return both RCTLinkingManager and RNFirebaseLinks
Any solution?
A bit late to answering this question, but the currently proposed answer will not work. It will fail to open actions from Firebase In-App Messaging since the returned NO from RNFirebaseLinks will get overwritten by RCTLinkingManager with YES for the restoration handler.
If you come across this, try the following:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handledLink = [[RNFirebaseLinks instance] application:application openURL:url options:options];
if (!handledLink) {
handledLink = [RCTLinkingManager application:application openURL:url options:options];
}
return handledLink;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
BOOL handleRestore = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
if (!handleRestore) {
handleRestore = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}
return handleRestore;
}
My current set up and need for this is react-navigation v3 and react-native-firebase v5
You can have something like the code below inside your restorationHandler function:
BOOL handled = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
if (!handled) {
handled = [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
return handled;
The solution for me was:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if (url == nil) return false;
BOOL handled = [[RNFirebaseLinks instance]
application:application
openURL:url
options:options
] || [RCTLinkingManager
application:application
openURL:url
options:options
];
return handled;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
BOOL handled = [[RNFirebaseLinks instance]
application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler
] || [RCTLinkingManager
application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler
];
return handled;
}
react-native-firebase: 5.5.6, react-navigation 3.X
Not controlling the url to nil was resulting to a crash when starting the app.
I am following all steps as per this link Click here
After doing all steps it gives me
Can anyone tell me this strange is happening ?
Answer would be appreciated.
Thanks.
Try those:
Add GIDSignIn library header properly, if in case you missing something.
Add AppDelgate.h file into your ViewController (If you not writing this code in AppDelegate.m)
Read point 4 which I copied from GitHub forum, which can be the main reason of your errors.
It looks like iOS 9 changed the constant UIApplicationLaunchOptionsSourceApplicationKey to UIApplicationOpenURLOptionsSourceApplicationKey. Dynamically support both, especially in Xcode 6.4 which doesn't recognize UIApplicationOpenURLOptionsSourceApplicationKey.
After try these all if its still not working then comment here for further help.
This is the AppDelegate.m file from which I implemented Google Signin SDK (the new one)
#define kGoogleClientID #""
#import "AppDelegate.h"
#import <GoogleSignIn/GoogleSignIn.h>
#interface AppDelegate ()<GIDSignInDelegate>
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GIDSignIn sharedInstance].clientID = kGoogleClientID;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if(annotation){
NSDictionary *options = #{UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication,
UIApplicationOpenURLOptionsAnnotationKey: annotation};
return [self application:application
openURL:url
options:options];
}
}
/* Google */
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations on signed in user here.
// ...
}
- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations when the user disconnects from app here.
// ...
}
#end
Hope this helps you out
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.