receive dynamic links on iOS
2018-03-03 07:19
465 查看
Receive Dynamic Links on iOS
To receive the Firebase Dynamic Links that you created, you must include the Dynamic Links SDK in your app and call thehandleUniversalLink:and
dynamicLinkFromCustomSchemeURL:methods when your app loads to get the data passed in the Dynamic Link.
Prerequisites
Firebase Dynamic Links requires iOS 8 or newer. You can target iOS 7 in your app, but all Firebase Dynamic Links SDK calls will be no-ops if the app isn't running on iOS 8 or newer.Set up Firebase and the Dynamic Links SDK
Add Firebase to your iOS project. Include the following pod in yourPodfile:pod 'Firebase/DynamicLinks'
Run
pod installand open the created
.xcworkspacefile.
In the Firebase console, open the Dynamic Links section.Accept the terms of service if you are prompted to do so.
Take note of your project's Dynamic Links domain, which is displayed at the top of the Dynamic Links page. You need your project's Dynamic Links domain to programmatically create Dynamic Links. A Dynamic Links domain look like
app_code.app.goo.gl.
On the image above the app_code is equal to abc123.
Ensure that your app's App Store ID and your App ID prefix is specified in your app's settings. To view and edit your app's settings, go to your Firebase project's Settings page and select your iOS app.You can confirm that your Firebase project is properly configured to use Dynamic Links in your iOS app by opening the following URL:https://app_code.app.goo.gl/apple-app-site-associationIf your app is connected, the
apple-app-site-associationfile contains a reference to your app's App ID prefix and bundle ID. For example:{"applinks":{"apps":[],"details":[{"appID":"1234567890.com.example.ios","paths":["/*"]}]}}If the
detailsfield is empty, double-check that you specified your App ID prefix. Note that your App ID prefix may not be the same as your Team ID.
Open Dynamic Links in your app
In the Info tab of your app's Xcode project, create a new URL type to be used for Dynamic Links. Set the Identifier field to a unique value and the URL scheme field to be your bundle identifier, which is the default URL scheme used by Dynamic Links.In the Capabilities tab of your app's Xcode project, enable Associated Domains and add the following to the Associated Domains list:applinks:app_code.app.goo.gl
Import the Firebase module in your
UIApplicationDelegate:
SWIFT
OBJECTIVE-C
@import Firebase;Configure a
FirebaseAppshared instance, typically in your application's
application:didFinishLaunchingWithOptions:method:
SWIFT
OBJECTIVE-C
// Use Firebase library to configure APIs[FIRApp configure];
Next, in the
application:continueUserActivity:restorationHandler:method, handle links received as Universal Links when the app is already installed (on iOS 9 and newer):
SWIFT
OBJECTIVE-C
- (BOOL)application:(UIApplication *)applicationcontinueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink * _Nullable dynamicLink,
NSError * _Nullable error) {
// ...
}];
return handled;
}
Finally, in the
application:openURL:sourceApplication:annotation:(iOS 8 and older) and
application:openURL:options:(iOS 9 and up) methods, handle links received through your app's custom URL scheme. These methods are called when your app receives a link on iOS 8 and older, and when your app is opened for the first time after installation on any version of iOS.If the Dynamic Link isn't found on your app's first launch (on any version of iOS), this method will be called with the
FIRDynamicLink's
urlset to
nil, indicating that the SDK failed to find a matching pending Dynamic Link.
SWIFT
OBJECTIVE-C
- (BOOL)application:(UIApplication *)appopenURL:(NSURL *)url
options:(NSDictionary<NSString *, id> *)options {
return [self application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
if (dynamicLink.url) {
// Handle the deep link. For example, show the deep-linked content,
// apply a promotional offer to the user's account or show customized onboarding view.
// ...
} else {
// Dynamic link has empty deep link. This situation will happens if
// Firebase Dynamic Links iOS SDK tried to retrieve pending dynamic link,
// but pending link is not available for this device/App combination.
// At this point you may display default onboarding view.
}
return YES;
}
return NO;
}
相关文章推荐
- Dynamic linking static library on iOS
- UE4 4.9 - cast modulated shadows causes flickering on IOS dynamic characters
- Getting started to receive your in-app for free on iOS(你懂的)
- How to share on Facebook obout iOS?
- iOS中 @synthesize 和 @dynamic 区别
- ios更新UI时请尝试使用performSelectorOnMainThread方法
- How to install IPA directly on your iOS! [iPhone/iPod/iPad]
- WebRTC ON iOS
- iOS toolchain for bash on windows
- Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial
- iOS 动态库(Dynamic框架)的创建以及引用添加(Embed Binary方式嵌入)
- iOS开发异常错误总结之——wait_fences: failed to receive reply: 10004003
- iOS 7 Tutorial Series: Dynamic Type
- kill application from other application on ios 6 using void kill dont work
- Cocoapods 报警告Automatically assigning platform ios with version 9.0 on target....
- [转]Blocking Code Injection on iOS and OS X
- Functional Reactive Programming on iOS with ReactiveCocoa
- wrestling-with-status-bars-and-navigation-bars-on-ios-7
- [Xcode] Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- IOS 被拒 关于 iPhone running iOS 10.3.1 on Wi-Fi connected to an IPv6 network.