Skip to content

Commit 19bf43a

Browse files
Merge pull request #509 from Iterable/tapash/mob-3567-swiftui-inbox
[MOB-3567] - SwiftUI inbox for sample app
2 parents c0736f0 + 6854b7a commit 19bf43a

File tree

6 files changed

+82
-16
lines changed

6 files changed

+82
-16
lines changed

sample-apps/swiftui-sample-app/swiftui-sample-app.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
AC5C7F6726E749B60067D6D7 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5C7F6626E749B60067D6D7 /* LoginView.swift */; };
2222
AC5C7F6926E7738E0067D6D7 /* DeeplinkHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5C7F6826E7738E0067D6D7 /* DeeplinkHandler.swift */; };
2323
AC5C7F6B26E778530067D6D7 /* AppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5C7F6A26E778530067D6D7 /* AppModel.swift */; };
24+
AC9AF7C2271F20CB00619392 /* InboxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC9AF7C1271F20CB00619392 /* InboxView.swift */; };
2425
ACEAACBC26EA00BA00D006AF /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACEAACBB26EA00BA00D006AF /* NotificationService.swift */; };
2526
ACEAACC026EA00BA00D006AF /* notification-extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = ACEAACB926EA00BA00D006AF /* notification-extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2627
ACEAACC626EA00DF00D006AF /* IterableAppExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = ACEAACC526EA00DF00D006AF /* IterableAppExtensions */; };
@@ -67,6 +68,7 @@
6768
AC5C7F6626E749B60067D6D7 /* LoginView.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; tabWidth = 2; };
6869
AC5C7F6826E7738E0067D6D7 /* DeeplinkHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeeplinkHandler.swift; sourceTree = "<group>"; };
6970
AC5C7F6A26E778530067D6D7 /* AppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppModel.swift; sourceTree = "<group>"; };
71+
AC9AF7C1271F20CB00619392 /* InboxView.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = InboxView.swift; sourceTree = "<group>"; tabWidth = 2; };
7072
ACEAACB426E9FA6100D006AF /* swiftui-sample-app.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "swiftui-sample-app.entitlements"; sourceTree = "<group>"; };
7173
ACEAACB926EA00BA00D006AF /* notification-extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "notification-extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
7274
ACEAACBB26EA00BA00D006AF /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
@@ -157,6 +159,7 @@
157159
AC5C7F5F26E7361A0067D6D7 /* Views */ = {
158160
isa = PBXGroup;
159161
children = (
162+
AC9AF7C0271F200500619392 /* Inbox */,
160163
AC59DB0626E0C489002A7E08 /* ContentView.swift */,
161164
AC5C7F6026E7364B0067D6D7 /* CoffeeListView.swift */,
162165
AC5C7F6226E7370D0067D6D7 /* CoffeeView.swift */,
@@ -166,6 +169,14 @@
166169
path = Views;
167170
sourceTree = "<group>";
168171
};
172+
AC9AF7C0271F200500619392 /* Inbox */ = {
173+
isa = PBXGroup;
174+
children = (
175+
AC9AF7C1271F20CB00619392 /* InboxView.swift */,
176+
);
177+
name = Inbox;
178+
sourceTree = "<group>";
179+
};
169180
ACEAACBA26EA00BA00D006AF /* notification-extension */ = {
170181
isa = PBXGroup;
171182
children = (
@@ -281,6 +292,7 @@
281292
buildActionMask = 2147483647;
282293
files = (
283294
AC5C7F6126E7364B0067D6D7 /* CoffeeListView.swift in Sources */,
295+
AC9AF7C2271F20CB00619392 /* InboxView.swift in Sources */,
284296
AC5C7F6326E7370E0067D6D7 /* CoffeeView.swift in Sources */,
285297
AC5C7F6B26E778530067D6D7 /* AppModel.swift in Sources */,
286298
AC5C7F6526E744700067D6D7 /* CoffeeRow.swift in Sources */,

sample-apps/swiftui-sample-app/swiftui-sample-app/AppModel.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ import SwiftUI
33

44
import IterableSDK
55

6+
enum SelectedTab {
7+
case home
8+
case inbox
9+
}
10+
611
class AppModel: ObservableObject {
712
static let shared = AppModel()
813

914
@Published
10-
var selectedCoffee: Coffee?
15+
var selectedTab: SelectedTab?
16+
17+
@Published
18+
var selectedCoffee: Coffee? {
19+
didSet {
20+
selectedTab = .home
21+
}
22+
}
1123

1224
@Published
1325
var email: String? = IterableAPI.email

sample-apps/swiftui-sample-app/swiftui-sample-app/MainApp.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
struct MainApp: App {
55
@UIApplicationDelegateAdaptor
66
private var appDelegate: AppDelegate
7-
7+
88
var body: some Scene {
99
WindowGroup {
1010
ContentView()
@@ -18,7 +18,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
1818
NotificationsHelper.shared.setupNotifications()
1919

2020
IterableHelper.initialize(launchOptions: launchOptions)
21-
21+
2222
return true
2323
}
2424

@@ -29,16 +29,16 @@ class AppDelegate: NSObject, UIApplicationDelegate {
2929
}
3030

3131
func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
32-
IterableHelper.register(token: deviceToken)
32+
IterableHelper.register(token: deviceToken)
3333
}
3434

3535
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
36-
fatalError()
36+
print("Failed to register token: \(error.localizedDescription)")
3737
}
3838

3939
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
4040
guard let url = userActivity.webpageURL else {
41-
return false
41+
return false
4242
}
4343

4444
return IterableHelper.handle(universalLink: url)

sample-apps/swiftui-sample-app/swiftui-sample-app/Views/ContentView.swift

+32-10
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,49 @@ struct ContentView: View {
77
@State
88
private var buttonText = "Login"
99

10+
@State
11+
private var selectedTab: SelectedTab = .home
12+
1013
var body: some View {
11-
NavigationView {
12-
CoffeeListView(coffees: Coffee.all)
13-
.toolbar {
14-
ToolbarItem(placement: .navigationBarTrailing) {
15-
Button(action: login) {
16-
VStack {
17-
Image(systemName: "person.circle")
18-
Text(buttonText)
14+
TabView(selection: $selectedTab) {
15+
NavigationView {
16+
CoffeeListView(coffees: Coffee.all)
17+
.toolbar {
18+
ToolbarItem(placement: .navigationBarTrailing) {
19+
Button(action: login) {
20+
VStack {
21+
Image(systemName: "person.circle")
22+
Text(buttonText)
23+
}
1924
}
2025
}
2126
}
22-
}
23-
.navigationTitle("Our Coffees")
27+
.navigationTitle("Our Coffees")
28+
}
29+
.tabItem {
30+
Image(systemName: "house")
31+
Text("Coffees")
32+
}
33+
.tag(SelectedTab.home)
34+
35+
NavigationView {
36+
InboxView()
37+
}
38+
.tabItem {
39+
Image(systemName: "envelope")
40+
Text("Inbox")
41+
}
42+
.tag(SelectedTab.inbox)
2443
}
2544
.onAppear {
2645
buttonText = (AppModel.shared.email == nil) ? "Login" : "Logout"
2746
}
2847
.onReceive(AppModel.shared.$email) { email in
2948
buttonText = (email == nil) ? "Login" : "Logout"
3049
}
50+
.onReceive(AppModel.shared.$selectedTab) { tab in
51+
selectedTab = tab ?? .home
52+
}
3153
.sheet(isPresented: $presentingLogin) {
3254
LoginView(isPresented: $presentingLogin)
3355
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Foundation
2+
import SwiftUI
3+
4+
import IterableSDK
5+
6+
struct InboxView: UIViewControllerRepresentable {
7+
typealias UIViewControllerType = IterableInboxViewController
8+
9+
func makeUIViewController(context: Context) -> IterableInboxViewController {
10+
let inbox = IterableInboxViewController()
11+
inbox.noMessagesTitle = "No Messages"
12+
inbox.noMessagesBody = "Please check back later"
13+
return inbox
14+
}
15+
16+
func updateUIViewController(_ uiViewController: IterableInboxViewController, context: Context) {
17+
}
18+
}

sample-apps/swiftui-sample-app/swiftui-sample-app/swiftui-sample-app.entitlements

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<dict>
55
<key>aps-environment</key>
66
<string>development</string>
7+
<key>com.apple.developer.usernotifications.time-sensitive</key>
8+
<true/>
79
</dict>
810
</plist>

0 commit comments

Comments
 (0)