Skip to content

Commit 8e909e5

Browse files
Open Google Notification.
1 parent 7ebbf50 commit 8e909e5

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

Tests/ui-tests/UITests.swift

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ class UITests: XCTestCase {
1515
app.launch()
1616
return app
1717
}()
18+
19+
static var monitor: NSObjectProtocol? = nil
1820

1921
// shortcut calculated property
2022
private var app: XCUIApplication {
2123
return UITests.application
2224
}
2325

26+
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
27+
2428
override func setUp() {
2529
// Put setup code here. This method is called before the invocation of each test method in the class.
2630

@@ -36,20 +40,24 @@ class UITests: XCTestCase {
3640
// Put teardown code here. This method is called after the invocation of each test method in the class.
3741
}
3842

39-
func testSetupNotifications() {
40-
app.buttons["Setup Notifications"].tap()
41-
let expectation1 = expectation(description: "Notification Setup")
42-
let monitor = addUIInterruptionMonitor(withDescription: "Getting Notification Permission") { (alert) -> Bool in
43-
let okButton = alert.buttons["Allow"]
44-
self.waitForElementToAppear(okButton)
45-
okButton.tap()
46-
expectation1.fulfill()
47-
return true
48-
}
49-
app.swipeUp()
43+
func testSendNotificationOpenGoogle() {
44+
allowNotificationsIfNeeded()
45+
46+
app.buttons["Send Notification"].tap()
47+
48+
let notification = springboard.otherElements["NotificationShortLookView"]
49+
XCTAssert(notification.waitForExistence(timeout: 10))
50+
51+
notification.swipeDown()
52+
53+
// Give one second pause before interacting
54+
sleep(1)
55+
56+
let button = SpringBoardNotification(springboard: springboard).buttonOpenGoogle
57+
button.tap()
5058

51-
wait(for: [expectation1], timeout: UITests.timeout)
52-
removeUIInterruptionMonitor(monitor)
59+
// Give some time to open
60+
sleep(1)
5361
}
5462

5563
func testShowSystemNotification() {
@@ -132,4 +140,29 @@ class UITests: XCTestCase {
132140
XCTFail("expected element: \(element)")
133141
}
134142
}
143+
144+
private func allowNotificationsIfNeeded() {
145+
app.buttons["Setup Notifications"].tap()
146+
UITests.monitor = addUIInterruptionMonitor(withDescription: "Getting Notification Permission") { (alert) -> Bool in
147+
let okButton = alert.buttons["Allow"]
148+
self.waitForElementToAppear(okButton)
149+
okButton.tap()
150+
if let monitor = UITests.monitor {
151+
self.removeUIInterruptionMonitor(monitor)
152+
}
153+
return true
154+
}
155+
// Xcode bug?, need to make this app active
156+
app.swipeUp()
157+
}
135158
}
159+
160+
struct SpringBoardNotification {
161+
let springboard: XCUIApplication
162+
163+
var buttonOpenGoogle: XCUIElement {
164+
return springboard.buttons["Open Google"].firstMatch
165+
}
166+
}
167+
168+

host-app/AppDelegate.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2121
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
2222
// Override point for customization after application launch.
2323

24+
let config = IterableConfig()
25+
config.customActionDelegate = self
26+
config.urlDelegate = self
2427
UserDefaults.standard.set("[email protected]", forKey: .ITBL_USER_DEFAULTS_EMAIL_KEY)
25-
IterableAPI.initialize(apiKey: "")
28+
IterableAPI.initialize(apiKey: "", config: config)
2629

2730
return true
2831
}
@@ -81,3 +84,22 @@ extension AppDelegate : UNUserNotificationCenterDelegate {
8184
}
8285
}
8386

87+
extension AppDelegate : IterableCustomActionDelegate {
88+
func handle(iterableCustomAction action: IterableAction, inContext context: IterableActionContext) -> Bool {
89+
ITBInfo("handleCustomAction: \(action)")
90+
return true
91+
}
92+
}
93+
94+
extension AppDelegate : IterableURLDelegate {
95+
func handle(iterableURL url: URL, inContext context: IterableActionContext) -> Bool {
96+
ITBInfo("handleUrl: \(url)")
97+
if url.absoluteString == "https://www.google.com" {
98+
// I am not going to handle this, do default
99+
return false
100+
} else {
101+
// I am handling this
102+
return true
103+
}
104+
}
105+
}

host-app/ViewController.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,26 @@ class ViewController: UIViewController {
173173
content.title = "Select"
174174
content.body = "Select an action"
175175
content.badge = NSNumber(value: 1)
176-
content.userInfo = [:]
176+
177+
let messageId = UUID().uuidString
178+
179+
let userInfo = [
180+
"itbl": [
181+
"campaignId" : 1234,
182+
"templateId" : 4321,
183+
"isGhostPush" : false,
184+
"messageId" : messageId,
185+
"actionButtons" : [[
186+
"identifier" : "Open Google",
187+
"buttonType" : "default",
188+
"action" : [
189+
"type" : "openUrl",
190+
"data" : "https://www.google.com"
191+
]]
192+
]
193+
]
194+
]
195+
content.userInfo = userInfo
177196

178197

179198
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false) // 10 seconds from now
@@ -184,7 +203,7 @@ class ViewController: UIViewController {
184203
@available(iOS 10.0, *)
185204
private func registerCategories() {
186205
ITBInfo()
187-
let tapButton1Action = UNNotificationAction(identifier: "Button1", title: "Tap Button 1", options: .foreground)
206+
let tapButton1Action = UNNotificationAction(identifier: "Open Google", title: "Open Google", options: .foreground)
188207
let tapButton2Action = UNNotificationAction(identifier: "Button2", title: "Tap Button 2", options: .destructive)
189208

190209
let category = UNNotificationCategory(identifier: "addButtonsCategory", actions: [tapButton1Action, tapButton2Action], intentIdentifiers: [])

swift-sdk/Internal/IterableAppIntegrationInternal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct IterableAppIntegrationInternal {
166166
tracker.trackPushOpen(userInfo, dataFields: dataFields)
167167
}
168168

169-
//Execute the action
169+
// Execute the action
170170
if let action = action {
171171
let context = IterableActionContext(action: action, source: .push)
172172
IterableActionRunner.execute(action: action,

0 commit comments

Comments
 (0)