Skip to content

Commit

Permalink
add deeplink test page
Browse files Browse the repository at this point in the history
Change-Id: I076cc5b21fc7b1e8e7d1bb5764363b74cd3eb4c2
  • Loading branch information
KirinelTT committed Aug 7, 2024
1 parent 876d624 commit f36a12a
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 110 deletions.
4 changes: 4 additions & 0 deletions TikTokBusinessSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
2B3368CC2BFCBF1E00E8D51C /* TikTokCurrencyUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B3368CA2BFCBF1E00E8D51C /* TikTokCurrencyUtility.m */; };
2B3368F92BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B3368F82BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.m */; };
2B3368FA2BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B3368F72BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.h */; };
2B4E17732C62A121003644EA /* DeeplinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B4E17722C62A121003644EA /* DeeplinkViewController.swift */; };
2B6C2D9A2BBAAFFB00D6D9E8 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 2B6C2D992BBAAFFB00D6D9E8 /* PrivacyInfo.xcprivacy */; };
2B870C022BF1F619009CB42C /* TikTokBaseEventTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B870C012BF1F619009CB42C /* TikTokBaseEventTests.m */; };
2B870C042BF1FB21009CB42C /* TikTokContentsEventTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B870C032BF1FB21009CB42C /* TikTokContentsEventTests.m */; };
Expand Down Expand Up @@ -180,6 +181,7 @@
2B3368CA2BFCBF1E00E8D51C /* TikTokCurrencyUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TikTokCurrencyUtility.m; sourceTree = "<group>"; };
2B3368F72BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TikTokSKAdNetworkRuleEvent.h; sourceTree = "<group>"; };
2B3368F82BFF1AE700E8D51C /* TikTokSKAdNetworkRuleEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TikTokSKAdNetworkRuleEvent.m; sourceTree = "<group>"; };
2B4E17722C62A121003644EA /* DeeplinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeeplinkViewController.swift; sourceTree = "<group>"; };
2B6C2D992BBAAFFB00D6D9E8 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
2B870C012BF1F619009CB42C /* TikTokBaseEventTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TikTokBaseEventTests.m; sourceTree = "<group>"; };
2B870C032BF1FB21009CB42C /* TikTokContentsEventTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TikTokContentsEventTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -446,6 +448,7 @@
children = (
8BB88F1D250A96CA00EC9D74 /* AppDelegate.swift */,
8BB88F21250A96CA00EC9D74 /* MainTableViewController.swift */,
2B4E17722C62A121003644EA /* DeeplinkViewController.swift */,
8BB88F36250A9A4100EC9D74 /* EventViewController.swift */,
2B1138532B9EEDC200215812 /* InitViewController.swift */,
2B1138552B9EF2A900215812 /* IdentifyViewController.swift */,
Expand Down Expand Up @@ -708,6 +711,7 @@
2B1138542B9EEDC200215812 /* InitViewController.swift in Sources */,
2B1138562B9EF2A900215812 /* IdentifyViewController.swift in Sources */,
8BB88F37250A9A4100EC9D74 /* EventViewController.swift in Sources */,
2B4E17732C62A121003644EA /* DeeplinkViewController.swift in Sources */,
8BB88F22250A96CA00EC9D74 /* MainTableViewController.swift in Sources */,
8BEA4661252E96F800E12E0E /* PurchaseViewController.swift in Sources */,
8BB88F1E250A96CA00EC9D74 /* AppDelegate.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "80F5921A-075F-4498-B6B5-A2A4165C0F0B"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TikTokBusinessSDK/TikTokSKAdNetworkSupport.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "96"
endingLineNumber = "96"
landmarkName = "-matchEventToSKANConfig:withValue:currency:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
<BreakpointContent
Expand Down Expand Up @@ -71,37 +55,5 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "938C628F-0D34-4CD6-A798-12CB94E77AFC"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TikTokBusinessSDK/TikTokPaymentObserver.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "41"
endingLineNumber = "41"
landmarkName = "+startObservingTransactions"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F5282077-C6A6-4659-B60D-74549121ED1C"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TikTokBusinessSDK/TikTokPaymentObserver.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "75"
endingLineNumber = "75"
landmarkName = "-startObservingTransactions"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
12 changes: 1 addition & 11 deletions TikTokBusinessSDK/AppEvents/TikTokAppEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* @brief Timer for flush
*/
@property (nonatomic, strong) NSTimer *flushTimer;

/**
* @brief Timer for logging
*/
@property (nonatomic, strong) NSTimer *logTimer;
@property (nonatomic, strong, nullable) NSTimer *flushTimer;

/**
* @brief Time in seconds until flush
Expand Down Expand Up @@ -75,11 +70,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)initializeFlushTimer;

/**
* @brief Initialize log timer
*/
- (void)initializeLogTimer;

/**
* @brief Clear cached events.
*/
Expand Down
24 changes: 8 additions & 16 deletions TikTokBusinessSDK/AppEvents/TikTokAppEventQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ - (id)init
return [self initWithConfig:nil];
}

- (void)dealloc
{
if (self.flushTimer) {
[self.flushTimer invalidate];
self.flushTimer = nil;
}
}

- (id)initWithConfig:(TikTokConfig *)config
{
self = [super init];
Expand All @@ -56,8 +64,6 @@ - (id)initWithConfig:(TikTokConfig *)config
[self initializeFlushTimer];
}

[self initializeLogTimer];

self.config = config;

self.logger = [TikTokFactory getLogger];
Expand Down Expand Up @@ -97,20 +103,6 @@ - (void)initializeFlushTimer
}];
}

- (void)initializeLogTimer
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.logTimer = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer *time) {
if([[defaults objectForKey:@"AreTimersOn"] isEqual: @"true"]){
NSDate *fireDate = [self.flushTimer fireDate];
NSDate *nowDate = [NSDate date];
self.timeInSecondsUntilFlush = [fireDate timeIntervalSinceDate:nowDate];

[[NSNotificationCenter defaultCenter] postNotificationName:@"timeLeft" object:nil];
}
}];
}

- (void)addEvent:(TikTokAppEvent *)event
{
if([[TikTokBusiness getInstance] isRemoteSwitchOn] == NO) {
Expand Down
5 changes: 5 additions & 0 deletions TikTokBusinessSDK/TikTokBusiness.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ + (void)resetInstance
}
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (id)init
{
self = [super init];
Expand Down
64 changes: 64 additions & 0 deletions TikTokBusinessSDKTestApp/DeeplinkViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// DeeplinkViewController.swift
// TikTokBusinessSDKTestApp
//
// Created by TikTok on 2024/8/6.
// Copyright © 2024 TikTok. All rights reserved.
//

import Foundation
import UIKit

class DeepLinkViewController: UIViewController {
private let textView = UITextView()
private let button = UIButton()
private let titleLabel = UILabel()

override func viewDidLoad() {
super.viewDidLoad()


view.backgroundColor = .white
titleLabel.text = "Enter DeepLink URL"
titleLabel.font = UIFont.boldSystemFont(ofSize: 20)
titleLabel.textColor = .black
titleLabel.textAlignment = .center
titleLabel.frame = CGRect(x: 20, y: 100, width: view.frame.width - 40, height: 30)
view.addSubview(titleLabel)

textView.layer.borderWidth = 1
textView.layer.cornerRadius = 8
textView.layer.borderColor = UIColor.lightGray.cgColor
textView.textContainerInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
textView.font = UIFont.systemFont(ofSize: 16)
textView.isScrollEnabled = true
textView.textColor = .black
textView.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
textView.frame = CGRect(x: 20, y: 150, width: view.frame.width - 40, height: view.frame.height / 3)
textView.autocapitalizationType = .none
view.addSubview(textView)


button.setTitle("open url", for: .normal)
button.setTitleColor(.white, for: .normal)
button.backgroundColor = UIColor(red: 0.2, green: 0.4, blue: 1.0, alpha: 1.0)
button.layer.cornerRadius = 20
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
button.frame = CGRect(x: 20, y: view.frame.height / 3 + 170, width: view.frame.width - 40, height: 40)
view.addSubview(button)
}

@objc private func buttonTapped() {
if let url = textView.text, let deepLink = URL(string: url) {
if UIApplication.shared.canOpenURL(deepLink) {
UIApplication.shared.open(deepLink, options: [:], completionHandler: nil)
} else {
// can't open url
print("Can't open this URL")
}
} else {
// invalid url
print("Please enter a valid URL")
}
}
}
5 changes: 4 additions & 1 deletion TikTokBusinessSDKTestApp/EventViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ class EventViewController: UIViewController {

finalPayloadTextView.frame = CGRect(x: 50, y: 200, width: 300, height: 200)
finalPayloadTextView.layer.borderWidth = 1
finalPayloadTextView.layer.borderColor = UIColor.black.cgColor
finalPayloadTextView.layer.cornerRadius = 8
finalPayloadTextView.layer.borderColor = UIColor.lightGray.cgColor
finalPayloadTextView.isScrollEnabled = true
finalPayloadTextView.textColor = .black
view.addSubview(finalPayloadTextView)

numberOfEventsField.frame = CGRect(x: 50, y: 410, width: 300, height: 40)
Expand Down
16 changes: 15 additions & 1 deletion TikTokBusinessSDKTestApp/InitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class InitViewController: UIViewController {
var appTrackingDialogSuppressedSwitch: UISwitch!
var SKAdNetworkSupportEnabledSwitch: UISwitch!
var LDUModeEnabledSwitch: UISwitch!
var statusLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -149,6 +150,12 @@ class InitViewController: UIViewController {
initButton.setTitle("Initialize SDK", for: .normal)
initButton.addTarget(self, action: #selector(initSDK), for: .touchUpInside)
view.addSubview(initButton)

statusLabel = UILabel(frame: CGRect(x: 20, y: 610, width: 300, height: 100))
statusLabel.numberOfLines = 0
statusLabel.lineBreakMode = .byWordWrapping
statusLabel.text = TikTokBusiness.isInitialized() ? "SDK initialized" : "SDK not initialized"
view.addSubview(statusLabel)
}

@objc func initSDK() {
Expand Down Expand Up @@ -196,7 +203,14 @@ class InitViewController: UIViewController {

*/
/* ADD LINE HERE */
TikTokBusiness.initializeSdk(config)
TikTokBusiness.initializeSdk(config) { success, error in
if (!success) {
print(error!.localizedDescription)
} else {
self.statusLabel.text = "SDK initialized"
TikTokBusiness.trackEvent("testEventinit")
}
}

/* UNCOMMENT TO CUSTOMIZE AFTER INITIALIZING SDK

Expand Down
6 changes: 3 additions & 3 deletions TikTokBusinessSDKTestApp/MainTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

class MainTableViewController: UITableViewController {
let options = ["Init", "Events", "Identify", "EventLogs", "Purchase"]
let options = ["Init", "Events", "Identify", "DeepLink", "Purchase"]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -43,8 +43,8 @@ class MainTableViewController: UITableViewController {
navigationController?.pushViewController(identifyVC, animated: true)
break
case 3:
// let eventLogsVC = PurchaseViewController()
// navigationController?.pushViewController(eventLogsVC, animated: true)
let deeplinkVC = DeepLinkViewController()
navigationController?.pushViewController(deeplinkVC, animated: true)
break
case 4:
let purchaseVC = PurchaseViewController()
Expand Down
8 changes: 8 additions & 0 deletions TikTokBusinessSDKTests/AppEvents/TikTokAppEventQueueTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ - (void)tearDown {
[TikTokBusiness resetInstance];
}

- (void)testIdentify {
[TikTokBusiness identifyWithExternalID:@"aaa" externalUserName:@"bbb" phoneNumber:@"ccc" email:@"ddd"];
}

- (void)testLogout {
[TikTokBusiness logout];
}

- (void)testAddEvent {
TikTokAppEvent *event = [[TikTokAppEvent alloc] initWithEventName:@"LaunchAPP"];

Expand Down
Loading

0 comments on commit f36a12a

Please sign in to comment.