[iOS / Obj-C] Firebase DynamicLink μμ±(2)
μ΄μ λ°μ μ±κ³΅μ΄λ€. Firebase console μμ μ€μ μλ£ν λ€μ΄ν°λΈ μμ€λ₯Ό μ§ννλ λ¨κ³μ΄λ€.
μ°Έκ³ μ¬μ΄νΈ
Firebase DynamicLinks Set up
https://firebase.google.com/docs/dynamic-links/ios/receive#objective-c_3
Firebase Quick Start Obj-C
ꡬνλ°©λ²
-
Associated Domains, URL Types μΆκ° Associated Domains μ applinks:escjunior.page.link μΆκ° (Associated Domains μμ κ²½μ° Capability μ + λ²νΌ λλ¬μ μΆκ°)
Targets β Info β URL Types μμ URL Schemes λ±λ‘
μ€μ! μ± Bundle ID λ‘ μ λ ₯ν΄μΌ ν¨
-
Podfile import FirebaseFirestore, FirebaseAuth, FirebaseDynamicLinks Podfileμ μ λ ₯ν terminal μ±μμ ν΄λΉ νλ‘μ νΈ κ²½λ‘ μ§μ ν pod install μ§ν
-
AppDelegate.m μμ€ μΆκ°
static NSString *const CUSTOM_URL_SCHEME = @"dlscheme";
// [START openurl]
- (BOOL)application:(UIApplication *)app
openURL:(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];
// ***μ¬κΈ°κ° dynamicLink μ€νλΆλΆ
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.
// [START_EXCLUDE]
// In this sample, we just open an alert.
[self handleDynamicLink:dynamicLink];
// [END_EXCLUDE]
} 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;
}
// [START_EXCLUDE silent]
// Show the deep link that the app was called with.
//[self showDeepLinkAlertViewWithMessage:[NSString stringWithFormat:@"openURL:\n%@", url]];
// [END_EXCLUDE]
return NO;
}
// [END openurl]
// [START continueuseractivity]
- (BOOL)application:(UIApplication *)application
continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif // __IPHONE_12_0
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink * _Nullable dynamicLink,
NSError * _Nullable error) {
// [START_EXCLUDE]
[self handleDynamicLink:dynamicLink];
// [END_EXCLUDE]
}];
// [START_EXCLUDE silent]
if (!handled) {
// Show the deep link URL from userActivity.
NSString *message = [NSString stringWithFormat:@"continueUserActivity webPageURL:\n%@",
userActivity.webpageURL];
[self showDeepLinkAlertViewWithMessage:message];
}
// [END_EXCLUDE]
return handled;
}
// [END continueuseractivity]
- (void)handleDynamicLink:(FIRDynamicLink *)dynamicLink {
NSString *matchConfidence;
if (dynamicLink.matchType == FIRDLMatchTypeWeak) {
matchConfidence = @"Weak";
} else {
matchConfidence = @"Strong";
}
NSString *message = [NSString stringWithFormat:@"App URL: %@\n"
@"Match Confidence: %@\nMinimum App Version:%@",
dynamicLink.url, matchConfidence, dynamicLink.minimumAppVersion];
//[self showDeepLinkAlertViewWithMessage:message];
NSString *myString = dynamicLink.url.absoluteString;
[[DataManager getInstance].webViewController loadURL:myString];
}
- (void)showDeepLinkAlertViewWithMessage:(NSString *)message {
NSString *title = @"Deep-link Data";
NSString *buttonTitle = @"OK";
if ([UIAlertController class]) {
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:buttonTitle
style:UIAlertActionStyleDefault
handler:nil]];
UIViewController *rootViewController = self.window.rootViewController;
[rootViewController presentViewController:alert animated:YES completion:nil];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:buttonTitle
otherButtonTitles:nil];
[alertView show];
}
}
λ! μ΄μ 1λ¨κ³μμ μ€μ ν https://escjunior.page.link/Tbeh λ§ν¬ μ μμ μ± λλ ν΄λΉ URLμ΄ λΈλΌμ°μ μμ μ΄λ¦Ό!ππ
Leave a comment