From e97c91fb6ce5efdfd3bde82fe812b6384967c822 Mon Sep 17 00:00:00 2001 From: ndixit-branch <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:45:10 -0700 Subject: [PATCH] SDK 2228 DMA Test automation (#1377) * Added features in Deep Link Demo App for testing setDMAParamsForEEARegion API. * Updated BranchSDK linking method to cocoaPod * Fixed Crash for Empty log File. * Updated logging API. * Added logging callback function for writing into text files * Fixed print function - Added locks and removed extra setLogFile call. --- .github/workflows/automation-trigger-test.yml | 3 - .../DeepLinkDemo.xcodeproj/project.pbxproj | 56 ++++--- DeepLinkDemo/DeepLinkDemo/AppDelegate.swift | 5 +- .../DeepLinkDemo/Base.lproj/Main.storyboard | 138 ++++++++++------- .../DeepLinkDemo/Constants/Utils.swift | 26 ++++ .../Controllers/GenerateURLVC.swift | 8 +- .../Controllers/HomeViewController.swift | 141 +++++++++++++++++- .../Controllers/TextViewController.swift | 14 +- .../Controllers/TrackContentVC.swift | 1 - .../DeepLinkDemo/NSURLSessionBranch.m | 33 ++-- DeepLinkDemo/Podfile | 2 + 11 files changed, 318 insertions(+), 109 deletions(-) diff --git a/.github/workflows/automation-trigger-test.yml b/.github/workflows/automation-trigger-test.yml index ae39e1c37..212c30e18 100644 --- a/.github/workflows/automation-trigger-test.yml +++ b/.github/workflows/automation-trigger-test.yml @@ -55,10 +55,7 @@ jobs: - name: Create and export DeepLinkDemo IPA file run: | - ./scripts/prep_static_xcframework.sh cd ./DeepLinkDemo - mkdir Framework - unzip ../Branch_static.zip -d ./Framework/ pod install xcodebuild -workspace DeepLinkDemo.xcworkspace -scheme DeepLinkDemo -sdk iphoneos archive -archivePath ./IPA/DeepLinkDemo.xcarchive xcodebuild -exportArchive -archivePath ./IPA/DeepLinkDemo.xcarchive -exportOptionsPlist IPA/Info.plist -exportPath IPA/ diff --git a/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj b/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj index 81a553764..5820cf513 100644 --- a/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj +++ b/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 1877918A283C8D2400229CD5 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18779189283C8D2400229CD5 /* Utils.swift */; }; 1889ACED283BE1C9009E3601 /* NSURLSessionBranch.m in Sources */ = {isa = PBXBuildFile; fileRef = 1889ACEC283BE1C9009E3601 /* NSURLSessionBranch.m */; }; 18AC5ADE283F61430098736E /* LogFileListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18AC5ADD283F61430098736E /* LogFileListViewController.swift */; }; + 2A2347C154C6746FA55C3649 /* Pods_DeepLinkDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDBB5A837B0C008CA5BEC1EF /* Pods_DeepLinkDemo.framework */; }; 7E1A39D42818289B002B302D /* DispalyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E1A39D32818289B002B302D /* DispalyVC.swift */; }; 7E2AE639280ED92800142446 /* CreateObjectReferenceObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E2AE638280ED92800142446 /* CreateObjectReferenceObject.swift */; }; 7E2AE63B280EE1F700142446 /* GenerateURLVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E2AE63A280EE1F700142446 /* GenerateURLVC.swift */; }; @@ -33,8 +34,6 @@ 7EE84374281CDFAE00A1561C /* StartupOptionsData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EE84373281CDFAE00A1561C /* StartupOptionsData.swift */; }; 7EF58D5B2812CF2300BA92D5 /* WebViewVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF58D5A2812CF2300BA92D5 /* WebViewVC.swift */; }; B7B7DC2A2859974E00D45FC5 /* TextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7B7DC292859974E00D45FC5 /* TextViewController.swift */; }; - E70E80C22A0E22C1008007B6 /* BranchSDK.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E70E80C12A0E22C1008007B6 /* BranchSDK.xcframework */; }; - E71086B529D2423100BDC598 /* Pods_DeepLinkDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA28D389F8D830715B437AAD /* Pods_DeepLinkDemo.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -47,8 +46,6 @@ 1889ACEB283BE1C9009E3601 /* NSURLSessionBranch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSURLSessionBranch.h; sourceTree = ""; }; 1889ACEC283BE1C9009E3601 /* NSURLSessionBranch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSURLSessionBranch.m; sourceTree = ""; }; 18AC5ADD283F61430098736E /* LogFileListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogFileListViewController.swift; sourceTree = ""; }; - 3ED981AAAEF5ECFF371D65F1 /* Pods-DeepLinkDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeepLinkDemo.debug.xcconfig"; path = "Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo.debug.xcconfig"; sourceTree = ""; }; - 7A19807506A47A88AF290FBF /* Pods-DeepLinkDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeepLinkDemo.release.xcconfig"; path = "Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo.release.xcconfig"; sourceTree = ""; }; 7E1A39D32818289B002B302D /* DispalyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DispalyVC.swift; sourceTree = ""; }; 7E2AE638280ED92800142446 /* CreateObjectReferenceObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateObjectReferenceObject.swift; sourceTree = ""; }; 7E2AE63A280EE1F700142446 /* GenerateURLVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateURLVC.swift; sourceTree = ""; }; @@ -72,8 +69,10 @@ 7EE84373281CDFAE00A1561C /* StartupOptionsData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartupOptionsData.swift; sourceTree = ""; }; 7EF58D5A2812CF2300BA92D5 /* WebViewVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewVC.swift; sourceTree = ""; }; 7EF58D5C2816D14700BA92D5 /* DeepLinkDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DeepLinkDemo.entitlements; sourceTree = ""; }; + 88EDCA13B444CE5565DC92FA /* Pods-DeepLinkDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeepLinkDemo.release.xcconfig"; path = "Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo.release.xcconfig"; sourceTree = ""; }; B7B7DC292859974E00D45FC5 /* TextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewController.swift; sourceTree = ""; }; - CA28D389F8D830715B437AAD /* Pods_DeepLinkDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DeepLinkDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + C06885D21868B25319262FC1 /* Pods-DeepLinkDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeepLinkDemo.debug.xcconfig"; path = "Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo.debug.xcconfig"; sourceTree = ""; }; + DDBB5A837B0C008CA5BEC1EF /* Pods_DeepLinkDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DeepLinkDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E70E80C12A0E22C1008007B6 /* BranchSDK.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = BranchSDK.xcframework; path = Framework/BranchSDK.xcframework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -82,8 +81,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E70E80C22A0E22C1008007B6 /* BranchSDK.xcframework in Frameworks */, - E71086B529D2423100BDC598 /* Pods_DeepLinkDemo.framework in Frameworks */, + 2A2347C154C6746FA55C3649 /* Pods_DeepLinkDemo.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -104,7 +102,7 @@ isa = PBXGroup; children = ( E70E80C12A0E22C1008007B6 /* BranchSDK.xcframework */, - CA28D389F8D830715B437AAD /* Pods_DeepLinkDemo.framework */, + DDBB5A837B0C008CA5BEC1EF /* Pods_DeepLinkDemo.framework */, ); name = Frameworks; sourceTree = ""; @@ -183,8 +181,8 @@ DB9F65A595474F5DA261D89A /* Pods */ = { isa = PBXGroup; children = ( - 3ED981AAAEF5ECFF371D65F1 /* Pods-DeepLinkDemo.debug.xcconfig */, - 7A19807506A47A88AF290FBF /* Pods-DeepLinkDemo.release.xcconfig */, + C06885D21868B25319262FC1 /* Pods-DeepLinkDemo.debug.xcconfig */, + 88EDCA13B444CE5565DC92FA /* Pods-DeepLinkDemo.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -196,11 +194,11 @@ isa = PBXNativeTarget; buildConfigurationList = 7E7477DA2809C46D0088A7D3 /* Build configuration list for PBXNativeTarget "DeepLinkDemo" */; buildPhases = ( - 4E20F2B3A080FBA467F97C22 /* [CP] Check Pods Manifest.lock */, + 8C8C5B24F34C07814525F311 /* [CP] Check Pods Manifest.lock */, 7E7477C22809C46C0088A7D3 /* Sources */, 7E7477C32809C46C0088A7D3 /* Frameworks */, 7E7477C42809C46C0088A7D3 /* Resources */, - 27F53A44E6856F363E13DC32 /* [CP] Embed Pods Frameworks */, + 9086714B33BB3D176E3DED70 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -261,43 +259,43 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 27F53A44E6856F363E13DC32 /* [CP] Embed Pods Frameworks */ = { + 8C8C5B24F34C07814525F311 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Embed Pods Frameworks"; + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-DeepLinkDemo-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 4E20F2B3A080FBA467F97C22 /* [CP] Check Pods Manifest.lock */ = { + 9086714B33BB3D176E3DED70 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-DeepLinkDemo-checkManifestLockResult.txt", + "${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -469,7 +467,7 @@ }; 7E7477DB2809C46D0088A7D3 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3ED981AAAEF5ECFF371D65F1 /* Pods-DeepLinkDemo.debug.xcconfig */; + baseConfigurationReference = C06885D21868B25319262FC1 /* Pods-DeepLinkDemo.debug.xcconfig */; buildSettings = { ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -517,7 +515,7 @@ }; 7E7477DC2809C46D0088A7D3 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7A19807506A47A88AF290FBF /* Pods-DeepLinkDemo.release.xcconfig */; + baseConfigurationReference = 88EDCA13B444CE5565DC92FA /* Pods-DeepLinkDemo.release.xcconfig */; buildSettings = { ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; diff --git a/DeepLinkDemo/DeepLinkDemo/AppDelegate.swift b/DeepLinkDemo/DeepLinkDemo/AppDelegate.swift index a95737288..bebb005e5 100644 --- a/DeepLinkDemo/DeepLinkDemo/AppDelegate.swift +++ b/DeepLinkDemo/DeepLinkDemo/AppDelegate.swift @@ -42,9 +42,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { IQKeyboardManager.shared().isEnabled = true StartupOptionsData.setActiveSetDebugEnabled(true) StartupOptionsData.setPendingSetDebugEnabled(true) - Branch.setBranchKey("key_test_om2EWe1WBeBYmpz9Z1mdpopouDmoN72T") - Branch.getInstance().enableLogging() - getBranchData(launchOptions) Utils.shared.setLogFile("AppDelegate") return true } @@ -145,7 +142,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { - fileprivate func getBranchData(_ launchOptions: [UIApplication.LaunchOptionsKey : Any]?) { + func getBranchData(_ launchOptions: [UIApplication.LaunchOptionsKey : Any]?) { Branch.getInstance().initSession( launchOptions: launchOptions, diff --git a/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard b/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard index 14411aff7..0e799346b 100644 --- a/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard +++ b/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -887,11 +887,11 @@ - - + + - + - - - - - - - - + + + + + + + + + + - + - - - - - + + + - - + + + @@ -1131,11 +1157,18 @@ + + + + - + + + + @@ -1159,6 +1192,8 @@ + + @@ -1169,7 +1204,7 @@ - + @@ -2218,6 +2253,7 @@ + @@ -2610,7 +2646,7 @@ - + diff --git a/DeepLinkDemo/DeepLinkDemo/Constants/Utils.swift b/DeepLinkDemo/DeepLinkDemo/Constants/Utils.swift index 137d498d9..b0182457b 100644 --- a/DeepLinkDemo/DeepLinkDemo/Constants/Utils.swift +++ b/DeepLinkDemo/DeepLinkDemo/Constants/Utils.swift @@ -57,5 +57,31 @@ class Utils: NSObject { freopen(cstr, "a+", stderr) } + + func printLogMessage(_ message: String) { + objc_sync_enter(self) + do { + print(message) // print to console + + if !FileManager.default.fileExists(atPath: logFileName!) { // does it exits? + FileManager.default.createFile(atPath: logFileName!, contents: nil) + } + + if let data = message.data(using: .utf8) { + let fileHandle = try FileHandle(forWritingTo: URL(fileURLWithPath: logFileName!)) + if #available(iOS 13.4, *) { + print(" ============= ********** Writing in file " + logFileName!) + try fileHandle.seekToEnd() + try fileHandle.write(contentsOf: data) + try fileHandle.close() + } else { + print("Unable to write log: iOS Version not supported") + } + } + } catch let error as NSError { // something wrong + print("Unable to write log: \(error.debugDescription)") // debug printout + } + objc_sync_exit(self) + } } diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/GenerateURLVC.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/GenerateURLVC.swift index f96afadd0..a1db4f8f6 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/GenerateURLVC.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/GenerateURLVC.swift @@ -88,7 +88,6 @@ class GenerateURLVC: ParentViewController { UserDefaults.standard.set("createdeeplinking", forKey: "isStatus") UserDefaults.standard.set(true, forKey: "isCreatedDeepLink") UserDefaults.standard.set("\(url ?? "")", forKey: "link") - if self.forNotification == true { self.fireLocalNotification(linkurl: "\(url ?? "")") self.launchTextViewController(url: "\(url ?? "")", message: alertMessage, forNotification: true) @@ -154,8 +153,10 @@ class GenerateURLVC: ParentViewController { if let fileContent = self.loadTextWithFileName(fileName), !fileContent.isEmpty { let startlocation = fileContent.range(of: "BranchSDK API LOG START OF FILE") let endlocation = fileContent.range(of: "BranchSDK API LOG END OF FILE") - let apiResponse = fileContent[startlocation!.lowerBound..() in + if (message.contains("BranchSDK")){ + self.logData = self.logData + message + "\n" + Utils.shared.printLogMessage(message + "\n") + } + } + AppDelegate.shared.getBranchData(AppDelegate.shared.launchOption) + branchSDKInitialized = true + } + + func logEvent(){ + let event = BranchEvent.standardEvent(.purchase) + // Add a populated `BranchUniversalObject` to the event + let buo = BranchUniversalObject(canonicalIdentifier: "item/12345") + event.contentItems = [ buo ] + // Add additional event data + event.alias = "my custom alias" + event.transactionID = "12344555" + event.eventDescription = "event_description" + event.searchQuery = "item 123" + event.customData = [ + "Custom_Event_Property_Key1": "Custom_Event_Property_val1", + "Custom_Event_Property_Key2": "Custom_Event_Property_val2" + ] + // Log the event + event.logEvent() + } + + func setDMAParamsWrapper() { + self.logData = "Error: Missing testData.\n" + + let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) + let vc = storyBoard.instantiateViewController(withIdentifier: "TextViewController") as? TextViewController + vc?.isSetDMAParams = true + + do { + let argCount = ProcessInfo.processInfo.arguments.count + if argCount >= 2 { + + for i in (1 ..< argCount) { + let data = ProcessInfo.processInfo.arguments[i].data(using: .utf8)! + + if let jsonObject = try JSONSerialization.jsonObject(with: data, options : .allowFragments) as? [String:AnyObject] + { + if ((jsonObject["dma_eea"] != nil) && (jsonObject["dma_eea"] != nil) && (jsonObject["dma_eea"] != nil)) { + let dma_eea = jsonObject["dma_eea"] as! Bool + let dma_ad_personalization = jsonObject["dma_ad_personalization"] as! Bool + let dma_ad_user_data = jsonObject["dma_ad_user_data"] as! Bool + self.logData = "" + self.enableBranchLogging(){(msg:String,msg2:BranchLogLevel,msg3:Error?)->() in + if (msg.contains("BranchSDK")){ + self.logData = self.logData + msg + "\n" + } + vc?.updateText(msg: self.logData) + } + if(self.branchSDKInitialized){ + Branch.getInstance().resetUserSession() + } + + Branch.setDMAParamsForEEA(dma_eea, adPersonalizationConsent: dma_ad_personalization, adUserDataUsageConsent: dma_ad_user_data) + AppDelegate.shared.getBranchData(AppDelegate.shared.launchOption) + self.branchSDKInitialized = true + } else { + self.logData = "Missing params from JSON Object: \n" + jsonObject.description + } + } else { + self.logData = "Bad JSON : \n" + ProcessInfo.processInfo.arguments[i] + } + } + + + } + } catch let error as NSError { + print(error) + self.logData += error.localizedDescription + } + vc?.updateText(msg: self.logData) + self.navigationController?.pushViewController(vc!, animated: true) + } + + func sendV2EventWrapper(){ + self.logData = "" + + let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) + let vc = storyBoard.instantiateViewController(withIdentifier: "TextViewController") as? TextViewController + + self.enableBranchLogging(){(msg:String,msg2:BranchLogLevel,msg3:Error?)->() in + if (msg.contains("BranchSDK")){ + self.logData = self.logData + msg + "\n" + vc?.updateText(msg: self.logData) + } + } + self.logEvent() + self.navigationController?.pushViewController(vc!, animated: true) + vc?.isSendV2Event = true + vc?.updateText(msg: self.logData) + self.branchSDKInitialized = true + } + @IBAction func sendNotificationAction(_ sender: Any) { reachabilityCheck(textValue: "sendNotification") } @@ -230,6 +359,14 @@ class HomeViewController: UITableViewController { } + + @IBAction func setDMAParams(){ + reachabilityCheck(textValue: "setDMAParams") + } + + @IBAction func sendV2Event(){ + reachabilityCheck(textValue: "sendV2Event") + } } extension UITextField { diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift index 4d70738a3..375a29036 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift @@ -21,6 +21,8 @@ class TextViewController: UIViewController { var isCreateDeepLink = false var forNotification = false var isTrackUser = false + var isSetDMAParams = false + var isSendV2Event = false var url = "" var responseStatus = "" @@ -62,7 +64,12 @@ class TextViewController: UIViewController { launchWebView() } else if self.isNavigateToContent || self.isDisplayContent || self.handleLinkInWebview { launchReadVC() - } else { + } else if self.isSetDMAParams == true { + self.navigationController?.popToRootViewController(animated: true) + } else if self.isSendV2Event == true { + self.navigationController?.popToRootViewController(animated: true) + } + else { launchReadVC() } } @@ -83,4 +90,9 @@ class TextViewController: UIViewController { } } + func updateText(msg: String) -> () { + DispatchQueue.main.async() { + self.logDataTextView?.text = msg + } + } } diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/TrackContentVC.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/TrackContentVC.swift index 2289d6b7a..9efe7653d 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/TrackContentVC.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/TrackContentVC.swift @@ -38,7 +38,6 @@ class TrackContentVC: ParentViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - Utils.shared.setLogFile("TrackContent") } diff --git a/DeepLinkDemo/DeepLinkDemo/NSURLSessionBranch.m b/DeepLinkDemo/DeepLinkDemo/NSURLSessionBranch.m index ec5c0d3e1..379c8e752 100644 --- a/DeepLinkDemo/DeepLinkDemo/NSURLSessionBranch.m +++ b/DeepLinkDemo/DeepLinkDemo/NSURLSessionBranch.m @@ -7,6 +7,7 @@ #import "NSURLSessionBranch.h" #import +#import "BranchLogger.h" @implementation NSURLSession (Branch) @@ -29,29 +30,31 @@ + (void)swizzleSelector:(SEL)originalSelector withSelector:(SEL)swizzledSelector } - (void)logNetworkTrafficRequest:(NSURLRequest *)request data:(NSData *)data response:(NSURLResponse *)response { - NSLog(@"BranchSDK API LOG START OF FILE"); - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"---------------------------------------------------------------------BranchSDK LOG START ---------------------------------------------------------------------" ); - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"BranchSDK Request log: %@", request); + [[BranchLogger shared] logDebug: @"BranchSDK API LOG START OF FILE" error:nil]; + + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:(@"---------------------------------------------------------------------BranchSDK LOG START ---------------------------------------------------------------------" ) error:nil]; + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:([NSString stringWithFormat: @"BranchSDK Request log: %@", request]) error:nil]; NSData *body = [request HTTPBody]; if (body) { - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"BranchSDK Request Body: %@", [NSString stringWithUTF8String:body.bytes]); + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"BranchSDK Request Body: %@", [NSString stringWithUTF8String:body.bytes]] error:nil]; } - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"BranchSDK Response: %@", response); + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"BranchSDK Response: %@", response] error:nil]; if (data.bytes) { - NSLog(@"\n\n"); - NSLog(@"BranchSDK Response Data: %@", [NSString stringWithUTF8String:data.bytes]); + [[BranchLogger shared] logDebug:(@"\n\n") error:nil]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"BranchSDK Response Data: %@", [NSString stringWithUTF8String:data.bytes]] error:nil]; } - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"---------------------------------------------------------------------BranchSDK LOG END ---------------------------------------------------------------------" ); - NSLog(@"[LogEntryStart]\n\n"); - NSLog(@"BranchSDK API LOG END OF FILE"); + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:(@"---------------------------------------------------------------------BranchSDK LOG END ---------------------------------------------------------------------" ) error:nil]; + [[BranchLogger shared] logDebug:(@"[LogEntryStart]\n\n") error:nil]; + [[BranchLogger shared] logDebug:(@"BranchSDK API LOG END OF FILE") error:nil]; + } // replacement method for dataTaskWithRequest diff --git a/DeepLinkDemo/Podfile b/DeepLinkDemo/Podfile index 80f3473a4..b7266ceb5 100644 --- a/DeepLinkDemo/Podfile +++ b/DeepLinkDemo/Podfile @@ -5,6 +5,8 @@ target 'DeepLinkDemo' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'IQKeyboardManager' + pod 'BranchSDK', :path => './../' + # Pods for DeepLinkDemo end