Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit eaf2dc7

Browse files
committed
modify example to use a SceneDelegate and add an example using SwiftUI
1 parent 264b227 commit eaf2dc7

File tree

15 files changed

+667
-12
lines changed

15 files changed

+667
-12
lines changed

Example/Podfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ target 'WeLoop_Example' do
66

77
target 'WeLoop_Tests' do
88
inherit! :search_paths
9-
10-
119
end
1210
end
11+
12+
target 'WeLoopSwiftUI' do
13+
pod 'WeLoop', :path => '../'
14+
end

Example/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- WeLoop (2.0.0)
2+
- WeLoop (2.0.1)
33

44
DEPENDENCIES:
55
- WeLoop (from `../`)
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
WeLoop: f875653e1280e963272a85fa875866b2faf794d2
12+
WeLoop: 5721a702ea954d22ba5c1b70353dd06d743135f4
1313

14-
PODFILE CHECKSUM: f2bbf31f07ce3fbb7efbfdc77822603ebfe51121
14+
PODFILE CHECKSUM: d353cdd091a31323387ecb211c13f0bbd9213d1b
1515

16-
COCOAPODS: 1.7.5
16+
COCOAPODS: 1.9.3

Example/WeLoop.xcodeproj/project.pbxproj

Lines changed: 223 additions & 3 deletions
Large diffs are not rendered by default.

Example/WeLoop/AppDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import WeLoop
1313
class AppDelegate: UIResponder, UIApplicationDelegate {
1414

1515
// This is a fake project GUID. Replace it with your actual project ID to test the example
16-
private let projectGUID = "496d6230-516a-11ea-99ea-f3431a995757"
16+
private let projectGUID = "e19340c0-b453-11e9-8113-1d4bacf0614e"
1717
private let user = User(id: "1", email: "[email protected]", firstName: "test1", lastName: "test2")
1818

19-
var window: UIWindow?
20-
2119
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
20+
21+
WeLoop.set(sceneBasedApplication: true)
2222

2323
// Set the invocation preferences. You can always change them after invoking the SDK
2424
WeLoop.set(invocationMethod: .fab)

Example/WeLoop/Info.plist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,26 @@
4343
</array>
4444
<key>UIViewControllerBasedStatusBarAppearance</key>
4545
<true/>
46+
<key>UIApplicationSceneManifest</key>
47+
<dict>
48+
<key>UIApplicationSupportsMultipleScenes</key>
49+
<false/>
50+
<key>UISceneConfigurations</key>
51+
<dict>
52+
<key>UIWindowSceneSessionRoleApplication</key>
53+
<array>
54+
<dict>
55+
<key>UISceneConfigurationName</key>
56+
<string>Default Configuration</string>
57+
<key>UISceneDelegateClassName</key>
58+
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
59+
<key>UISceneStoryboardFile</key>
60+
<string>Main</string>
61+
</dict>
62+
</array>
63+
</dict>
64+
</dict>
65+
<key>UIApplicationSupportsIndirectInputEvents</key>
66+
<true/>
4667
</dict>
4768
</plist>

Example/WeLoop/SceneDelegate.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// SceneDelegate.swift
3+
// SceneDelegateExample
4+
//
5+
// Created by Henry Huck on 04/12/2020.
6+
//
7+
8+
import UIKit
9+
10+
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
11+
12+
var window: UIWindow?
13+
14+
15+
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
16+
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
17+
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
18+
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
19+
guard let _ = (scene as? UIWindowScene) else { return }
20+
}
21+
22+
func sceneDidDisconnect(_ scene: UIScene) {
23+
// Called as the scene is being released by the system.
24+
// This occurs shortly after the scene enters the background, or when its session is discarded.
25+
// Release any resources associated with this scene that can be re-created the next time the scene connects.
26+
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
27+
}
28+
29+
func sceneDidBecomeActive(_ scene: UIScene) {
30+
// Called when the scene has moved from an inactive state to an active state.
31+
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
32+
}
33+
34+
func sceneWillResignActive(_ scene: UIScene) {
35+
// Called when the scene will move from an active state to an inactive state.
36+
// This may occur due to temporary interruptions (ex. an incoming phone call).
37+
}
38+
39+
func sceneWillEnterForeground(_ scene: UIScene) {
40+
// Called as the scene transitions from the background to the foreground.
41+
// Use this method to undo the changes made on entering the background.
42+
}
43+
44+
func sceneDidEnterBackground(_ scene: UIScene) {
45+
// Called as the scene transitions from the foreground to the background.
46+
// Use this method to save data, release shared resources, and store enough scene-specific state information
47+
// to restore the scene back to its current state.
48+
}
49+
}
50+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// AppDelegate.swift
3+
// WeLoopSwiftUI
4+
//
5+
// Created by Henry Huck on 06/12/2020.
6+
// Copyright © 2020 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import WeLoop
11+
12+
@main
13+
class AppDelegate: UIResponder, UIApplicationDelegate {
14+
15+
// This is a fake project GUID. Replace it with your actual project ID to test the example
16+
private let projectGUID = "e19340c0-b453-11e9-8113-1d4bacf0614e"
17+
private let user = User(id: "1", email: "[email protected]", firstName: "test1", lastName: "test2")
18+
19+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
20+
21+
WeLoop.set(sceneBasedApplication: true)
22+
23+
// Set the invocation preferences. You can always change them after invoking the SDK
24+
WeLoop.set(invocationMethod: .fab)
25+
26+
WeLoop.set(delegate: self)
27+
WeLoop.initialize(apiKey: projectGUID);
28+
WeLoop.authenticateUser(user: user)
29+
return true
30+
}
31+
32+
// MARK: UISceneSession Lifecycle
33+
34+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
35+
// Called when a new scene session is being created.
36+
// Use this method to select a configuration to create the new scene with.
37+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
38+
}
39+
40+
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
41+
// Called when the user discards a scene session.
42+
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
43+
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
44+
}
45+
}
46+
47+
48+
extension AppDelegate: WeLoopDelegate {
49+
50+
func initializationSuccessful() {
51+
// From this point forward, we can safely invoke the Widget manually
52+
}
53+
54+
func initializationFailed(with error: Error) {
55+
// Initialization Failed (no network for example). Based on the error you'll have to retry the initialization later.
56+
print(error)
57+
}
58+
59+
func failedToLaunch(with error: Error) {
60+
// The widget could not be launched. Most likely is that the initialization process failed, or the user is missing in autoAuthentication
61+
print(error)
62+
}
63+
64+
func notificationCountUpdated(newCount: Int) {
65+
print(newCount)
66+
}
67+
}
68+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"scale" : "2x",
6+
"size" : "20x20"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"scale" : "3x",
11+
"size" : "20x20"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"scale" : "2x",
16+
"size" : "29x29"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"scale" : "3x",
21+
"size" : "29x29"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"scale" : "2x",
26+
"size" : "40x40"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"scale" : "2x",
51+
"size" : "20x20"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"scale" : "1x",
56+
"size" : "29x29"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"scale" : "2x",
61+
"size" : "29x29"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"scale" : "1x",
66+
"size" : "40x40"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"scale" : "2x",
71+
"size" : "40x40"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
92+
}
93+
],
94+
"info" : {
95+
"author" : "xcode",
96+
"version" : 1
97+
}
98+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

0 commit comments

Comments
 (0)