วิธีที่มีประสิทธิภาพที่สุดวิธีหนึ่งในการทำให้ผู้ใช้ใหม่ติดตั้งแอปของคุณคือการทำให้ผู้ใช้สามารถแชร์เนื้อหาจากแอปของคุณกับเพื่อนๆ ได้ ด้วยไดนามิกลิงก์ คุณสามารถสร้างประสบการณ์การแชร์ระหว่างผู้ใช้กับผู้ใช้ที่ยอดเยี่ยม: ผู้ใช้ที่ได้รับคำแนะนำเนื้อหาจากเพื่อนของพวกเขาสามารถคลิกลิงก์และถูกนำไปยังเนื้อหาที่แบ่งปันในแอปของคุณโดยตรง แม้ว่าพวกเขาจะต้องไปที่แอป Store หรือ Google Play Store เพื่อติดตั้งแอปของคุณก่อน
ด้วยการรวมความเหนียวแน่นของการอ้างอิงผู้ใช้และความคงอยู่ของลิงก์แบบไดนามิก คุณสามารถสร้างคุณลักษณะการแบ่งปันแบบผู้ใช้กับผู้ใช้และการอ้างอิงที่นำผู้ใช้ใหม่เข้ามาโดยการดึงดูดผู้ใช้โดยตรงไปยังเนื้อหาของแอปของคุณหรือแสดงการส่งเสริมการขายที่ให้ประโยชน์ร่วมกันแก่ผู้อ้างอิงและผู้อ้างอิง .
ประโยชน์ที่สำคัญ
- ผู้ใช้ใหม่ที่เปิดแอปของคุณเป็นครั้งแรกจะได้รับประสบการณ์ใช้งานครั้งแรกที่ปรับแต่งตามบริบทโดยอิงตามสิ่งที่เพื่อนของพวกเขาต้องการแบ่งปันกับพวกเขา ตัวอย่างเช่น คุณสามารถแสดงเนื้อหาที่แบ่งปันกับพวกเขา หรือเชื่อมต่อพวกเขาโดยอัตโนมัติกับเพื่อนที่เชิญพวกเขา
- ทำให้ผู้ใช้สามารถแชร์เนื้อหากับเพื่อน ๆ ข้ามแพลตฟอร์มได้อย่างง่ายดาย ไม่ว่าเพื่อน ๆ ของพวกเขาจะติดตั้งแอปของคุณหรือไม่ก็ตาม
นี่คือวิธีการเริ่มต้น!
ตั้งค่า Firebase และ Dynamic Links SDK
ตั้งค่าโปรเจ็กต์ Firebase ใหม่ และติดตั้ง Dynamic Links SDK ลงในแอปของคุณ
การติดตั้ง Dynamic Links SDK ช่วยให้ Firebase ส่งต่อข้อมูลเกี่ยวกับ Dynamic Link ไปยังแอป รวมถึงหลังจากที่ผู้ใช้ติดตั้งแอปแล้ว
สร้างลิงก์แบบไดนามิก
ตอนนี้ได้เวลาตั้งค่าลิงก์ที่ผู้ใช้สามารถส่งให้เพื่อนได้แล้ว ไม่ต้องกังวลหากเพื่อนของผู้ใช้ยังไม่ได้ติดตั้งแอป ลิงก์แบบไดนามิกสามารถจัดการให้คุณได้
สำหรับแต่ละองค์ประกอบของเนื้อหาที่คุณต้องการแชร์ ให้ สร้างลิงก์แบบไดนามิก
เมื่อคุณสร้างลิงก์แบบไดนามิก คุณจะต้องระบุ HTTP หรือ HTTPS URL เป็นพารามิเตอร์ link
ที่จะใช้เพื่อระบุเนื้อหาที่คุณกำลังแบ่งปัน หากคุณมีเว็บไซต์ที่มีเนื้อหาเทียบเท่ากัน คุณควรใช้ URL ของเว็บไซต์ของคุณ เพื่อให้แน่ใจว่าลิงก์เหล่านี้แสดงผลอย่างถูกต้องบนแพลตฟอร์มที่ไม่รองรับลิงก์แบบไดนามิก เช่น เบราว์เซอร์บนเดสก์ท็อป ตัวอย่างเช่น:
https://example.page.link/?link=https://www.example.com/content?item%3D1234&apn=com.example.android&ibi=com.example.ios&isi=12345
คุณยังสามารถเพิ่มข้อมูลเพิ่มเติมให้กับเพย์โหลดข้อมูลโดยเพิ่มพารามิเตอร์ที่เข้ารหัส URL ตัวอย่างเช่น เพื่อระบุว่าลิงก์นั้นมีไว้สำหรับผู้ใช้เฉพาะ เช่น ในคำเชิญเล่นเกม
https://example.page.link/?link=https://www.example.com/invitation?gameid%3D1234%26referrer%3D555&apn=com.example.android&ibi=com.example.ios&isi=12345
ก่อนที่คุณจะแชร์ลิงก์เหล่านี้ คุณอาจต้องการใช้ API ตัวย่อ URL ของลิงก์แบบไดนามิกของ Firebase เพื่อสร้าง URL ที่ดูเป็นมิตร ลิงก์ไดนามิกสั้นๆ มีลักษณะดังนี้:
https://example.page.link/WXYZ
ไม่ว่าคุณจะใช้ลิงก์ใด เมื่อผู้ใช้เปิดลิงก์แบบไดนามิกบนอุปกรณ์ของตน แอปที่ระบุโดยพารามิเตอร์ apn
(บน Android) หรือพารามิเตอร์ ibi
และ isi
(บน iOS) จะนำผู้ใช้ไปที่ Play Store หรือ App Store เพื่อติดตั้งแอป หากยังไม่ได้ติดตั้ง จากนั้น เมื่อติดตั้งและเปิดแอปแล้ว URL ที่ระบุในพารามิเตอร์ 'ลิงก์' จะถูกส่งผ่านไปยังแอป
เพิ่มปุ่ม "แบ่งปัน" ที่ส่งลิงก์แบบไดนามิก
ก่อนอื่น มาดูตัวอย่างง่ายๆ ของแอปแชทตามห้อง เช่น แฮงเอาท์ ที่สร้างลิงก์เพื่อเชิญคนมาที่ห้องแชท
iOS


แอนดรอยด์


สวิฟต์
func generateContentLink() -> URL { let baseURL = URL(string: "https://your-custom-name.page.link")! let domain = "https://your-app.page.link" let linkBuilder = DynamicLinkComponents(link: baseURL, domainURIPrefix: domain) linkBuilder?.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.your.bundleID") linkBuilder?.androidParameters = DynamicLinkAndroidParameters(packageName: "com.your.packageName") // Fall back to the base url if we can't generate a dynamic link. return linkBuilder?.link ?? baseURL }
วัตถุประสงค์-C
- (NSURL *)generateContentLink { NSURL *baseURL = [NSURL URLWithString:@"https://your-custom-name.page.link"]; NSString *domain = @"https://your-app.page.link"; FIRDynamicLinkComponents *builder = [[FIRDynamicLinkComponents alloc] initWithLink:baseURL domainURIPrefix:domain]; builder.iOSParameters = [FIRDynamicLinkIOSParameters parametersWithBundleID:@"com.your.bundleID"]; builder.androidParameters = [FIRDynamicLinkAndroidParameters parametersWithPackageName:@"com.your.packageName"]; // Fall back to the base url if we can't generate a dynamic link. return builder.link ?: baseURL; }
Kotlin+KTX
fun generateContentLink(): Uri { val baseUrl = Uri.parse("https://your-custom-name.page.link") val domain = "https://your-app.page.link" val link = FirebaseDynamicLinks.getInstance() .createDynamicLink() .setLink(baseUrl) .setDomainUriPrefix(domain) .setIosParameters(DynamicLink.IosParameters.Builder("com.your.bundleid").build()) .setAndroidParameters(DynamicLink.AndroidParameters.Builder("com.your.packageName").build()) .buildDynamicLink() return link.uri }
Java
public static Uri generateContentLink() { Uri baseUrl = Uri.parse("https://your-custom-name.page.link"); String domain = "https://your-app.page.link"; DynamicLink link = FirebaseDynamicLinks.getInstance() .createDynamicLink() .setLink(baseUrl) .setDomainUriPrefix(domain) .setIosParameters(new DynamicLink.IosParameters.Builder("com.your.bundleid").build()) .setAndroidParameters(new DynamicLink.AndroidParameters.Builder("com.your.packageName").build()) .buildDynamicLink(); return link.getUri(); }
เมื่อคุณมีลิงก์แบบไดนามิกแล้ว คุณสามารถเพิ่มปุ่มแชร์ไปที่ UI ของคุณ ซึ่งจะเปิดใช้โฟลว์การแชร์แพลตฟอร์มมาตรฐาน:
สวิฟต์
lazy private var shareController: UIActivityViewController = { let activities: [Any] = [ "Learn how to share content via Firebase", URL(string: "https://firebase.google.com")! ] let controller = UIActivityViewController(activityItems: activities, applicationActivities: nil) return controller }() @IBAction func shareButtonPressed(_ sender: Any) { let inviteController = UIStoryboard(name: "Main", bundle: nil) .instantiateViewController(withIdentifier: "InviteViewController") self.navigationController?.pushViewController(inviteController, animated: true) }
วัตถุประสงค์-C
- (UIActivityViewController *)shareController { if (_shareController == nil) { NSArray *activities = @[ @"Learn how to share content via Firebase", [NSURL URLWithString:@"https://firebase.google.com"] ]; UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil]; _shareController = controller; } return _shareController; } - (IBAction)shareLinkButtonPressed:(UIView *)sender { if (![sender isKindOfClass:[UIView class]]) { return; } self.shareController.popoverPresentationController.sourceView = sender; [self presentViewController:self.shareController animated:YES completion:nil]; }
Kotlin+KTX
private fun onShareClicked() { val link = DynamicLinksUtil.generateContentLink() val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, link.toString()) startActivity(Intent.createChooser(intent, "Share Link")) }
Java
private void onShareClicked() { Uri link = DynamicLinksUtil.generateContentLink(); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, link.toString()); startActivity(Intent.createChooser(intent, "Share Link")); }
ในตัวอย่างนี้ UI การแชร์เริ่มต้นจะแสดงรายการแอปสำหรับการแชร์ลิงก์โดยอัตโนมัติ ดังนั้นจึงเป็นสิ่งที่คุณสามารถตั้งค่าในแอปของคุณเองด้วยโค้ดเพียงไม่กี่บรรทัด
แทนที่จะให้ผู้ใช้เลือกผู้ติดต่อและเขียนข้อความในแอปของคุณ การกระทำเหล่านี้จะได้รับมอบสิทธิ์ให้กับแอปที่พวกเขาเลือกจากกล่องโต้ตอบการแชร์ นอกจากนี้ การมอบสิทธิ์การแชร์ให้กับแอปอื่นหมายความว่าคุณไม่จำเป็นต้องขอสิทธิ์ในการติดต่อจากผู้ใช้ และอนุญาตให้ผู้ใช้เลือกจากรายชื่อผู้ติดต่อที่ขยายภายในแอปที่เลือก เพื่ออำนวยความสะดวกในการแบ่งปันทางสังคมให้ดียิ่งขึ้น คุณสามารถ เพิ่มข้อมูลเมตาตัวอย่างโซเชียลมีเดีย ลงในลิงก์ไดนามิกของคุณซึ่งจะแสดงพร้อมกับลิงก์ในช่องทางโซเชียลหลักๆ
แม้ว่าบางครั้ง การส่งลิงก์เปล่าๆ ที่ไม่มีข้อความไม่เพียงพอสำหรับการอ้างอิงที่น่าสนใจ ด้วยการแนบลิงก์พร้อมข้อความสั้น ๆ และถ้าเป็นไปได้ การนำเสนอที่สมบูรณ์ยิ่งขึ้น ผู้ใช้สามารถเข้าใจคุณค่าของผู้อ้างอิงเมื่อพวกเขาได้รับ:
iOS


แอนดรอยด์


แม้ว่าสิ่งนี้จะซับซ้อนกว่าตัวอย่างที่แล้ว แต่วิธีการจะเหมือนกันไม่มากก็น้อย บนหน้าจอนี้มีกราฟิกขนาดใหญ่พร้อมคุณค่าของคำเชิญและปุ่มสำหรับแชร์ไปยังช่องทางโซเชียลหลักๆ มีความซ้ำซ้อนในโฟลว์ UI นี้ ช่องการแชร์บางช่องจะแสดงแยกกันเพื่อให้สามารถปรับแต่งข้อความเฉพาะช่องได้มากขึ้น เช่น การเพิ่มบรรทัดชื่อเรื่องในคำเชิญทางอีเมล ในเมนูคำเชิญนี้ เรา:
- แสดงปุ่มแชร์อีเมล ข้อความ และคัดลอกลิงก์ และปรับแต่งข้อความให้เหมาะสม อีเมลจะรวมหัวเรื่องและสามารถรวมเนื้อหาที่ยาวขึ้นพร้อมการขึ้นบรรทัดใหม่ รูปภาพ และการเว้นวรรค ข้อความควรมีเนื้อหาที่สั้นลงพร้อมการขึ้นบรรทัดใหม่แต่เว้นวรรคน้อยและไม่มีรูปภาพ และการคัดลอกลิงก์ควรคัดลอกลิงก์เท่านั้นและไม่มีอะไรอย่างอื่น
- ใช้ UI ที่ใช้ร่วมกันของระบบสำหรับสิ่งอื่นๆ รวมถึงข้อความเชิญสั้นๆ ที่มาพร้อมกับลิงก์
- ลิงก์ในรายละเอียดผ่านรูปแบบ URL หรือลิงก์สากลไปยังแอปอื่นที่มีตรรกะพิเศษสำหรับจัดการคำเชิญของแอป การดำเนินการนี้ใช้ไม่ได้นอกการเป็นพาร์ทเนอร์ทางธุรกิจระหว่างองค์กรของคุณกับแอปอื่นๆ และอาจไม่ใช่ตัวเลือกสำหรับองค์กรขนาดเล็ก กล่าวคือ แอปบางแอปอาจบันทึกพฤติกรรมสากล/ลิงก์ในรายละเอียดต่อสาธารณะ เราจะใช้เวอร์ชันจำลองนี้ในตัวอย่างของเรา
ขั้นแรก กำหนดประเภทเนื้อหาคำเชิญ ซึ่งจะสรุปเฉพาะข้อมูลในคำเชิญและไม่มีฟังก์ชันการทำงานใดๆ ด้วยวิธีนี้ คุณสามารถเริ่มต้นด้วยประเภทข้อมูลและคิดเกี่ยวกับโค้ดของคุณในแง่ของวิธีการรวมข้อมูลเข้าด้วยกัน
สวิฟต์
/// The content within an invite, with optional fields to accommodate all presenters. /// This type could be modified to also include an image, for sending invites over email. struct InviteContent { /// The subject of the message. Not used for invites without subjects, like text message invites. var subject: String? /// The body of the message. Indispensable content should go here. var body: String? /// The URL containing the invite. In link-copy cases, only this field will be used. var link: URL }
วัตถุประสงค์-C
/// The content within an invite, with optional fields to accommodate all presenters. /// This type could be modified to also include an image, for sending invites over email. @interface InviteContent : NSObject <NSCopying> /// The subject of the message. Not used for invites without subjects, like text message invites. @property (nonatomic, readonly, nullable) NSString *subject; /// The body of the message. Indispensable content should go here. @property (nonatomic, readonly, nullable) NSString *body; /// The URL containing the invite. In link-copy cases, only this field will be used. @property (nonatomic, readonly) NSURL *link; - (instancetype)initWithSubject:(nullable NSString *)subject body:(nullable NSString *)body link:(NSURL *)link NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; @end
Kotlin+KTX
/** * The content of an invitation, with optional fields to accommodate all presenters. * This type could be modified to also include an image, for sending invites over email. */ data class InviteContent( /** The subject of the message. Not used for invites without subjects, like SMS. */ val subject: String?, /** The body of the message. Indispensable content should go here. */ val body: String?, /** The URL containing the link to invite. In link-copy cases, only this field will be used. */ val link: Uri )
Java
/** * The content of an invitation, with optional fields to accommodate all presenters. * This type could be modified to also include an image, for sending invites over email. */ public class InviteContent { /** * The subject of the message. Not used for invites without subjects, like SMS. **/ @Nullable public final String subject; /** * The body of the message. Indispensable content should go here. **/ @Nullable public final String body; /** * The URL containing the link to invite. In link-copy cases, only this field will be used. **/ @NonNull public final Uri link; public InviteContent(@Nullable String subject, @Nullable String body, @NonNull Uri link) { // ... } }
ข้อมูลที่จำเป็นเพียงอย่างเดียวที่นี่คือ URL ซึ่งคุณจะไม่สามารถเชิญผู้ใช้มาที่แอปของคุณได้ ส่วนข้อมูลอื่นๆ มีโครงสร้างอย่างชัดเจนสำหรับการส่งอีเมล ซึ่งทำให้บางกรณีรู้สึกอึดอัดใจเล็กน้อย เมื่อส่งคำเชิญผ่านข้อความ ข้อความประกาศที่มาพร้อมกับลิงก์อาจอ่านคล้ายกับหัวเรื่องอีเมล แต่เมื่อแชร์ไปยังโซเชียลมีเดีย ข้อความประกอบลิงก์อาจดูเหมือนเนื้อหาอีเมลมากกว่า คุณจะต้องทดลองด้วยตัวคุณเองเพื่อหาสมดุลที่ดีที่สุดสำหรับแอปของคุณ และหากคุณไม่แน่ใจ คุณสามารถใช้บริการเช่น การกำหนดค่าระยะไกลได้ ตลอดเวลาเพื่อให้คุณเปลี่ยนค่าข้อความหลังจากเปิดใช้แอป
สวิฟต์
/// A type responsible for presenting an invite given using a specific method /// given the content of the invite. protocol InvitePresenter { /// The name of the presenter. User-visible. var name: String { get } /// An icon representing the invite method. User-visible. var icon: UIImage? { get } /// Whether or not the presenter's method is available. iOS devices that aren't phones /// may not be able to send texts, for example. var isAvailable: Bool { get } /// The content of the invite. Some of the content type's fields may be unused. var content: InviteContent { get } /// Designated initializer. init(content: InviteContent, presentingController: UIViewController) /// This method should cause the presenter to present the invite and then handle any actions /// required to complete the invite flow. func sendInvite() }
วัตถุประสงค์-C
/// A type responsible for presenting an invite given using a specific method /// given the content of the invite. @protocol InvitePresenter <NSObject> /// The name of the presenter. User-visible. @property (nonatomic, readonly) NSString *name; /// An icon representing the invite method. User-visible. @property (nonatomic, readonly, nullable) UIImage *icon; /// Whether or not the presenter's method is available. iOS devices that aren't phones /// may not be able to send texts, for example. @property (nonatomic, readonly) BOOL isAvailable; /// The content of the invite. Some of the content type's fields may be unused. @property (nonatomic, readonly) InviteContent *content; /// Designated initializer. - (instancetype)initWithContent:(InviteContent *)content presentingViewController:(UIViewController *)controller; /// This method should cause the presenter to present the invite and then handle any actions /// required to complete the invite flow. - (void)sendInvite; @end
Kotlin+KTX
/** * Presents the invite using a specific method, such as email or social. */ open class InvitePresenter( /** The user-visible name of the invite method, like 'Email' or 'SMS' */ val name: String, /** An icon representing the invite method. */ @param:DrawableRes @field:DrawableRes val icon: Int, /** Whether or not the method is available on this device. For example, SMS is phone only. */ val isAvailable: Boolean, /** The Content of the invitation */ val content: InviteContent ) { /** * Send the invitation using the specified method. */ open fun sendInvite(context: Context) { // ... } }
Java
/** * Presents the invite using a specific method, such as email or social. */ public class InvitePresenter { /** * The user-visible name of the invite method, like 'Email' or 'SMS' **/ public final String name; /** * An icon representing the invite method. **/ @DrawableRes public final int icon; /** * Whether or not the method is available on this device. For example, SMS is phone only. **/ public final boolean isAvailable; /** * The Content of the invitation **/ public final InviteContent content; public InvitePresenter(String name, @DrawableRes int icon, boolean isAvailable, InviteContent content) { // ... } /** * Send the invitation using the specified method. */ public void sendInvite(Context context) { // ... } }
ตอนนี้สิ่งที่เหลืออยู่คือเสียบสิ่งนี้เข้ากับองค์ประกอบ UI ที่คุณเลือก สำหรับการนำโฟลว์คำเชิญนี้ไปใช้อย่างเต็มรูปแบบ โปรดดูตัวอย่างบน GitHub สำหรับ iOS และ Android
ทั้งหมดนี้เป็นวิธีการทำให้ผู้ใช้ของคุณสามารถส่งคำเชิญถึงเพื่อน ซึ่งเป็นโซลูชันคำเชิญที่มีขนาดเล็กที่สุด แอพยอดนิยมหลายตัวยังส่งคำเชิญด้วยการส่งอีเมลผ่านแบ็กเอนด์ของตัวเอง ซึ่งจำเป็นต้องผสานรวมบริการส่งเมล แต่มอบสิทธิประโยชน์มากมายที่ไม่มีในที่อื่นพร้อมข้อเสียเล็กน้อยเพียงเล็กน้อยเท่านั้น
ข้อดี:
- เปิดใช้งานอีเมลที่มีมาร์กอัปที่ซับซ้อนซึ่งผู้ใช้ของคุณไม่สามารถแก้ไขได้ก่อนส่ง
- เปิดใช้งานการติดตาม/การวิเคราะห์ที่ละเอียดยิ่งขึ้น (เช่น ส่งความสำเร็จและความล้มเหลวในแบ็กเอนด์ของคุณ)
จุดด้อย:
- อีเมลมีแนวโน้มที่จะถูกระบุว่าเป็นสแปม
- ต้องผสานรวมกับบริการจัดส่งอีเมล
- ต้องการสิทธิ์ผู้ติดต่อในแอป
โดยทั่วไปแล้ว การส่งคำเชิญผ่านบริการจัดส่งทางอีเมลของคุณเองจะมอบประสบการณ์การเชิญที่สม่ำเสมอและอาจสมบูรณ์ยิ่งขึ้นด้วยต้นทุนที่หลากหลาย
เปิดเนื้อหาที่เชื่อมโยงในแอปของคุณ
สุดท้าย คุณต้องได้รับลิงก์ที่ส่งไปยังแอปของคุณ คุณจึงจะสามารถแสดงเนื้อหาที่เชื่อมโยงไปยังผู้รับได้ ทำได้ง่ายโดยใช้ Dynamic Links SDK:
iOS
บน iOS คุณจะได้รับลิงก์แบบไดนามิกโดยการใช้เมธอด application:continueUserActivity:restorationHandler:
: ในตัวจัดการการคืนค่า คุณสามารถรับลิงก์ไดนามิกได้โดยการเรียก handleUniversalLink:completion:
หากลิงก์แบบไดนามิกถูกส่งไปยังแอปของคุณ คุณสามารถรับได้จากคุณสมบัติ url
ของ FIRDynamicLink
ตัวอย่างเช่น:
วัตถุประสงค์-C
[[FIRDynamicLinks dynamicLinks]
handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink * _Nullable dynamicLink,
NSError * _Nullable error) {
NSString *link = dynamicLink.url;
BOOL strongMatch = dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong;
// ...
}];
สวิฟต์
FIRDynamicLinks.dynamicLinks()?.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
let link = dynamicLink.url
let strongMatch = dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong
// ...
}
นอกจากนี้ คุณต้องเรียก dynamicLinkFromCustomSchemeURL:
ใน application:openURL:options:
method เพื่อรับ Dynamic Links ที่ส่งผ่านไปยังแอปของคุณเป็น URL แบบแผนที่กำหนดเอง ตัวอย่างเช่น:
วัตถุประสงค์-C
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
NSString *link = dynamicLink.url;
BOOL strongMatch = dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong;
// ...
return YES;
}
สวิฟต์
let dynamicLink = FIRDynamicLinks.dynamicLinks()?.dynamicLinkFromCustomSchemeURL(url)
if let dynamicLink = dynamicLink {
let link = dynamicLink.url
let strongMatch = dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong
// ...
return true
}
เมื่อคุณมีค่าของพารามิเตอร์ link
แล้ว คุณสามารถแสดงเนื้อหาที่ลิงก์ไปยังผู้รับ หรือประมวลผลข้อมูลที่ระบุโดยพารามิเตอร์ด้วยวิธีอื่น ไลบรารีการกำหนดเส้นทาง URL เช่น JLRoutes สามารถช่วยงานนี้ได้
หากคุณได้รับลิงก์ที่มีไว้สำหรับผู้รับเฉพาะ ตรวจสอบให้แน่ใจว่าความเชื่อมั่นในการจับคู่ของไดนามิกลิงก์นั้น strong
ก่อนที่จะเรียกใช้ตรรกะเฉพาะของผู้ใช้
แอนดรอยด์
บน Android คุณใช้เมธอด getDynamicLink()
เพื่อรับข้อมูลจากลิงก์ไดนามิก:
Kotlin+KTX
Firebase.dynamicLinks .getDynamicLink(intent) .addOnCompleteListener { task -> if (!task.isSuccessful) { // Handle error // ... } val invite = FirebaseAppInvite.getInvitation(task.result) if (invite != null) { // Handle invite // ... } }
Java
FirebaseDynamicLinks.getInstance() .getDynamicLink(getIntent()) .addOnCompleteListener(new OnCompleteListener<PendingDynamicLinkData>() { @Override public void onComplete(@NonNull Task<PendingDynamicLinkData> task) { if (!task.isSuccessful()) { // Handle error // ... } FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(task.getResult()); if (invite != null) { // Handle invite // ... } } });
เมื่อคุณมีค่าของพารามิเตอร์ link
แล้ว คุณสามารถแสดงเนื้อหาที่ลิงก์ไปยังผู้รับ หรือประมวลผลข้อมูลที่ระบุโดยพารามิเตอร์ด้วยวิธีอื่น ไลบรารีการกำหนดเส้นทาง URL สามารถช่วยงานนี้ได้