Skip to content

Commit

Permalink
Merge pull request #116 from vespinola/fix/creative
Browse files Browse the repository at this point in the history
Multiple Creative Instances
  • Loading branch information
jasonaden authored Oct 15, 2024
2 parents 6f6d281 + bba71fd commit 9e65c9c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Example/CreativeUITest/CreativeUITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase {
HomePage.tapOnPushMeToCreative()

CreativePage
.addDelay(seconds: 1)
.addDelay(seconds: 3)
.tapOnPrivacyLink()

guard canLaunchExternalApps else { return }
Expand Down
2 changes: 1 addition & 1 deletion Example/CreativeUITest/Pages/CreativePage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fileprivate extension CreativePage {
}

static var privacyLink: XCUIElement {
app.webViews.links["Privacy"]
app.webViews.links["Privacy link will open in a new tab"]
}

static var debugStaticText: XCUIElement {
Expand Down
8 changes: 4 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
INFOPLIST_KEY_UIStatusBarStyle = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -482,7 +482,7 @@
INFOPLIST_KEY_UIStatusBarStyle = "";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -626,7 +626,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -661,7 +661,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '10.0'
platform :ios, '14.0'

target 'Example - Pod' do
# The 'use_frameworks!' option builds the pods as dynamic frameworks instead of static libs.
Expand Down
12 changes: 6 additions & 6 deletions ExampleSwift/ExampleSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.6;
Expand Down Expand Up @@ -460,7 +460,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.6;
Expand Down Expand Up @@ -503,7 +503,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.6;
Expand Down Expand Up @@ -548,7 +548,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.6;
Expand Down Expand Up @@ -604,8 +604,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/attentive-mobile/attentive-ios-sdk";
requirement = {
branch = main;
kind = branch;
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
11 changes: 10 additions & 1 deletion Sources/Public/SDK/ATTNSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ public typealias ATTNCreativeTriggerCompletionHandler = (String) -> Void

@objc(ATTNSDK)
public final class ATTNSDK: NSObject {
var isCreativeOpen = false
static var _isCreativeOpen: Bool = false

var isCreativeOpen: Bool {
get {
ATTNSDK._isCreativeOpen
}
set {
ATTNSDK._isCreativeOpen = newValue
}
}

// MARK: Instance Properties
var parentView: UIView?
Expand Down
17 changes: 17 additions & 0 deletions Tests/TestCases/ATTNSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,22 @@ final class ATTNSDKTests: XCTestCase {
XCTAssertTrue(creativeUrlProviderSpy.buildCompanyCreativeUrlWasCalled)
XCTAssertEqual(creativeUrlProviderSpy.usedCreativeId, creativeId)
}

func testIsCreativeOpen_whenThereAreTwoSDKInstancesAndBothTriggersCreative_ShouldNotLaunchASecondCreative() {
ATTNSDK._isCreativeOpen = false
let secondCreativeUrlProviderSpy = ATTNCreativeUrlProviderSpy()
let secondSdk = ATTNSDK(api: apiSpy, urlBuilder: secondCreativeUrlProviderSpy)

XCTAssertFalse(ATTNSDK._isCreativeOpen, "The value should be false")
sut.trigger(UIView())
XCTAssertTrue(creativeUrlProviderSpy.buildCompanyCreativeUrlWasCalled, "Creative url should be built")

secondSdk.trigger(UIView())
XCTAssertTrue(secondCreativeUrlProviderSpy.buildCompanyCreativeUrlWasCalled, "Creative url should not be built")

addTeardownBlock {
ATTNSDK._isCreativeOpen = false
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/attentive-mobile/attentive-ios-sdk",
"state" : {
"branch" : "main",
"revision" : "16ea6c5924b6431d996f38d057b9a55e6639ed03"
"revision" : "6f6d281e63eee0e7a894524d5d461a74ab8837f0",
"version" : "1.0.0"
}
}
],
Expand Down

0 comments on commit 9e65c9c

Please sign in to comment.