|
| 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 | + |
0 commit comments