I am implementing Universal Links in my app. Every things works for me, except when the app is not running in the background. In that case how i can open a specific page in my app? iOS launches my app but i am not getting any callback in
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
in this function neither i am getting any url with this line
NSURL *launchURL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
inside
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions this function.
Does anybody have an idea how i can get the url which caused to launch my application.
Thanks
You can access to your url in this way ...
NSDictionary *aux = [launchOptions objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey];
if (aux) {
NSUserActivity *activity = [aux objectForKey:#"UIApplicationLaunchOptionsUserActivityKey"];
NSString *urlString = activity.webpageURL.absoluteString;
}
But for better use you have to validate this URL and return YES if you can manage it
For example ...
if([urlString hasPrefix:#"https://myUrl.com"]) {
return YES;
}
.. after this the method
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
It will be called
When you open a Universal Link with your app
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options
is called with the Universal Link as a parameter and options if it is the case. Check apple docs for details.
In Swift 5 with a SceneDelegate file it will call:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { }
When your app is NOT running in background and user clicks on a universal link.
You need to implement
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation{
url= yourappurl://with some app link data
sourceApplication= //who called your application
}
For example if your app is called from facebook messenger, then you will get
sourceApplication=#"com.facebook.messenger"
Related
I struggled with dynamic links for days. Appreciate any help, please.
I integrate firebase dynamic links, if I paste the link in chrome url and press enter, it can open app with event triggered and url passed
but if I click the open button on the preview page, it always open App store regardless whether the app installed or not
Any thoughts?
I have browsed all posts on the web, but no good luck.
"react-native": "^0.59.5"
"react-native-firebase": "^5.3.1"
pod 'Firebase/Core', '~> 5.20.1'
pod 'Firebase/DynamicLinks', '~> 5.20.1'
Domain on firebase console: https://links.umrgo.com/links
bundle id: com.umrgo.www.umr-app-ios
URL Types identifier: links.umrgo.com
URL Types identifier: com.umrgo.www.umr-app-ios
capabilities: applinks:links.umrgo.com
release build
I also add FirebaseDynamicLinksCustomDomains with a array of string
https://links.umrgo.com
Some of my codes are as below.
[FIROptions defaultOptions].deepLinkURLScheme = #"com.umrgo.www.umr-app-ios";
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
options:(NSDictionary<NSString*, id> *)options
{
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;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL handled = [RCTLinkingManager
application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
return handled;
}
const link = new firebase.links.DynamicLink(`https://www.umrgo.com/publish/${publishId}?publishType=${publishType}&publishId=${publishId}&otherUserUnionId=${currentUserUnionId}&conversationId=${conversationId}`,
'links.umrgo.com/links').android.setPackageName(conf.GooglePackageName).ios.setBundleId(conf.AppleBundleId).ios.setAppStoreId(conf.AppleAppID);
firebase.links()
.createShortDynamicLink(link, 'UNGUESSABLE')
.then((url) => {
var payload = {
key: createLinkUniqueKey(conversationId, publishId, currentUserUnionId, publishType),
url: url,
publish_id: publishId,
target_user_unionid: currentUserUnionId,
conversation_id: conversationId,
publish_type: publishType
}
axios.post(getApiEndpoint(conf.UMRApiUrls.createDynamicLinkRemote), payload, {
headers: getAuthHeader()
}).then(response => {
console(response)
})
});
Some snapshots are below:
redirect to app store
ask for open app
enter link in browser and press enter
app open with url passed if enter link in browser
bottom right is the app, release build
You mentioned pasting link into a browser. If you do this in Safari, it will intentionally not go directly to your app because the device is assuming that your intent is to open a web page. If you tap on a link, it could act differently. It's possible that Chrome is following this same idea.
This answer provides some good testing steps to make sure it's working right: https://stackoverflow.com/a/44817701/2612222
I want to use both Firebase UI (for signup/login) and Facebook SDK (for sharing/posting) in my React Native app.
Both SDKs want to control the application:(UIApplication *)app openURL:(NSURL *)url handler.
Here's Facebook openURL code and Firebase UI openURL.
What is the correct way to combine the two snippets? I've come up with the code below, but neither SDK explains what URLs do they handle and when, so I'm not sure which one should execute first?
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
id annotation = options[UIApplicationOpenURLOptionsAnnotationKey];
BOOL handled = [[FUIAuth defaultAuthUI] handleOpenURL:url sourceApplication:sourceApplication];
if (!handled) {
handled = [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}
return handled;
}
Im trying to implement the new Google SignIn Library that I installed using Cocoapods. Deployment Target is 8.4 and Im testing in a 9.0.2 device.
1- I have the proper plist file with clientID and reverseID
2- I have the URL types set
3- I have the AppDelegate as a delegate of GIDSignIn [GIDSignIn sharedInstance].delegate = self; and the proper delegate methods implemented to catch the callback - (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error
4- I have the - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{ return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
5- Im using the automatic GIDSignInButton class and is placed in a subclass of UIViewController, so I dont need to implement the GIDSignIn uiDelegate methods. But I still have [[GIDSignIn sharedInstance] setUiDelegate:self]; set in the viewDidLoad
6- I have SFSafariViewController.framework in the Linked Libraries.
7- I never manually set the clientID to GIDSignIn because that is not part of the instructions at google's official documentation. Although many people keep doing it I dont know why.
The Problem: Once I press the Login button, a SFSafariViewController gets presented, I select the account I want to use (notice it never went out of my app into any other google apps for authentication even though I have several installed). The permissions get presented, I see the name & logo of my app that I configured in Google Developer Console, I accept the permissions. The SFSafariViewController falls back to "www.google.com" and thats it. The only way to dismiss this screen is to tap on the "OK" button in the uppper right corner, and then the - (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error gets called, with error saying the used Cancelled the login process.
Just solve it. As you are using CocoaPods, seems like you have to set
Swift:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
}
Obj-c
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
in your appDelegate. Now you will be redirected to your app after accepting the permissions.
More info: https://developers.google.com/identity/sign-in/ios/sign-in
I found out the problem. Google Official Documentation mentions the need to implement the following method in your AppDelegate
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
But it never mentions the need to implement also a similar method called
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
I had to implement both methods in order for my app to work properly. I have facebook authentication too, so my methods ended up looking like the following.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]
|| [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
] ||
[[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
i am using Linkedin SDK in ios.
i am using following code to authenticate the user
[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil]
state:nil//#"some state"
showGoToAppStoreDialog:YES
successBlock:^(NSString *returnState) {
}
errorBlock:^(NSError *error) {
}
];
by using this code , i am able to open linkedin app but unable to get callback from linkedin app to my app.
Not Getting call on
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"%s url=%#","app delegate application openURL called ", [url absoluteString]);
if ([LISDKCallbackHandler shouldHandleUrl:url]) {
return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
return YES;
}
i am using "liMY_APPID" in URL Schemes.And also try from LinkedIn iOS SDK Bundle Suffix
Please help me how i can get callback from linkedin app
Make sure if you are using iOS 9.0 or higher as base SDK since
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
is deprecated from iOS 9. Instead use
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options
Use options[UIApplicationLaunchOptionsSourceApplicationKey] and options[UIApplicationLaunchOptionsAnnotationKey] for sourceApplication and annotation respectively.
Example:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
if ([LISDKCallbackHandler shouldHandleUrl:url]) {
return [LISDKCallbackHandler application:app openURL:url sourceApplication:options[UIApplicationLaunchOptionsSourceApplicationKey] annotation:options[UIApplicationLaunchOptionsAnnotationKey]];
}
return YES;
}
Your code is correct only but your problem is related to URL schemes...
Add the same URL scheme in your info.plist file what you have mentioned in "iOS URL Suffix Schemes" so that once linkedIn will call the same URL scheme, Might be you have used incorrect URL scheme in your app.
URL scheme is nothing but it is a link to open your application. If you enter your URL scheme in mobile safari i.e.
testApp://
it will open your app (If installed). Using following process you can add it in your project
right-click on your info.plist and choose Open As – Source Code:
right-click on your info.plist and select Show Raw Keys/Values, the output will look as follows:
check link for more details to add custom URL schemes
ISSUE RESOLVED
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if LISDKCallbackHandler.shouldHandle(url) {
LISDKCallbackHandler.application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
return true
}
Did you add the LIAppId property to your Info.plist?
Have you added all your bundles to LinkedIn dev's center for iOS? If not, copy your bundle id and add it to https://www.linkedin.com/developer/apps/APP_ID/mobile and do not forget to Save.
I use a URL scheme to open my app and parse the query string from the URL in -didFinishLaunchingWithOptions:. This works great, but it doesn't parse the new string when the app becomes active. I have implemented the -handleOpenURL: and openURL methods as follows, but neither seems to be called when the app becomes active...
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url)
return NO;
queryStrings = [self parseQueryString:[url query]];
return YES;
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (!url)
return NO;
queryStrings = [self parseQueryString:[url query]];
return YES;
}
Please help! Thanks!
Use:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
The method you're using is deprecated.
handleOpenURL is deprecated on iOS 5: you should be using application:openURL:sourceApplication:annotation: instead - have you got an application:openURL method in your app as well? If not, add one and see if it gets picked up.
To clarify the above accepted answer. You probably want to use this (I was confused by the accepted answer as it only includes the function you need and not what you need to include inside the function):
- (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]];
}
I personally came to this issue through the Ray Wenderlich tutorial. There are also some good tutorials using Parse which show how to integrate the two.
The full tutorial this leads up to and from this point can be found here: https://parse.com/tutorials/integrating-facebook-in-ios
Hopefully this helps lessen confusion around this issue :)