Skip to content

Commit

Permalink
Fix Push Notifications for Android and iOS in Capacitor SDK (#161)
Browse files Browse the repository at this point in the history
* Added the initial code for iOS PN handling

* incorrect param was being extracted in android level

* added comment on incorrect branch key format

* updated the definition of BranchUrlParams

---------

Co-authored-by: vamsimadhav <[email protected]>
Co-authored-by: vamsi-branch <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 343c755 commit 9984834
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/co/boundstate/BranchDeepLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void sendError(String error) {
public void handleUrl(PluginCall call) {
// https://help.branch.io/developers-hub/docs/android-advanced-features#section-handle-links-in-your-own-app

String branchUrl = call.getString("url");
String branchUrl = call.getString("branch");

if (branchUrl != null && !branchUrl.equals("")) {
Intent intent = new Intent(getActivity(), getActivity().getClass());
Expand Down
9 changes: 9 additions & 0 deletions ios/Plugin/BranchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ class BranchService {
func setDMAParamsForEEA(eeaRegion: Bool, adPersonalizationConsent: Bool, adUserDataUsageConsent: Bool) -> Void {
Branch.setDMAParamsForEEA(eeaRegion, adPersonalizationConsent: adPersonalizationConsent, adUserDataUsageConsent: adUserDataUsageConsent)
}

func handleUrl(url: String, completion: @escaping (Error?) -> Void) {
if let deepLinkUrl = URL(string: url) {
Branch.getInstance().handleDeepLink(deepLinkUrl)
completion(nil)
} else {
completion(NSError(domain: "Invalid URL", code: 400, userInfo: nil))
}
}
}
1 change: 1 addition & 0 deletions ios/Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
CAP_PLUGIN_METHOD(getLatestReferringParams, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getFirstReferringParams, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(setDMAParamsForEEA, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(handleUrl, CAPPluginReturnPromise);
)
15 changes: 15 additions & 0 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,19 @@ public class BranchDeepLinks: CAPPlugin {
branchService.setDMAParamsForEEA(eeaRegion: eeaRegion, adPersonalizationConsent: adPersonalizationConsent, adUserDataUsageConsent: adUserDataUsageConsent)
call.resolve()
}

@objc func handleUrl(_ call: CAPPluginCall) {
guard let url = call.getString("branch") else {
call.reject("The object passed must contain a 'branch' key with a string value")
return
}

branchService.handleUrl(url: url) { error in
if let error = error {
call.reject(error.localizedDescription)
} else {
call.resolve()
}
}
}
}
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface BranchReferringParamsResponse {
}

export interface BranchUrlParams {
url: string;
branch: string;
}

export interface BranchShortUrlAnalytics {
Expand Down

0 comments on commit 9984834

Please sign in to comment.