Move CallExampleContext ownership to the AppDelegate. When receiving a PushIncoming call, register (else call won’t work)
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
@ObservedObject var tutorialContext = CallExampleContext()
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
|
||||
@@ -43,6 +43,7 @@ class CallExampleContext : ObservableObject
|
||||
let outgoingCallName = "Outgoing call example"
|
||||
let incomingCallName = "Incoming call example"
|
||||
|
||||
|
||||
init()
|
||||
{
|
||||
mProviderDelegate = CallKitProviderDelegate(context : self)
|
||||
@@ -60,13 +61,12 @@ class CallExampleContext : ObservableObject
|
||||
|
||||
// Initialize Linphone Core
|
||||
|
||||
try? mCore = factory.createCore(configPath: "MyConfig", factoryConfigPath: "", systemContext: nil)
|
||||
try? mCore = factory.createCore(configPath: "", factoryConfigPath: "", systemContext: nil)
|
||||
|
||||
// main loop for receiving notifications and doing background linphonecore work:
|
||||
mCore.autoIterateEnabled = true
|
||||
mCore.callkitEnabled = true
|
||||
mCore.pushNotificationEnabled = true
|
||||
|
||||
|
||||
let pushConfig = mCore.pushNotificationConfig!
|
||||
pushConfig.provider = "apns.dev"
|
||||
@@ -106,6 +106,12 @@ class CallExampleContext : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
func clearRegistrations()
|
||||
{
|
||||
mCore.clearProxyConfig()
|
||||
loggedIn = false
|
||||
}
|
||||
|
||||
|
||||
func createCallParams() throws -> CallParams
|
||||
{
|
||||
@@ -213,6 +219,11 @@ class CallStateDelegate: CoreDelegate {
|
||||
|
||||
if (cstate == .PushIncomingReceived)
|
||||
{
|
||||
if (!tutorialContext.loggedIn)
|
||||
{
|
||||
// Cannot properly answer call if not registered. If the app was launched from a push notification, register.
|
||||
tutorialContext.registrationExample()
|
||||
}
|
||||
// We're being called by someone (and app is in background)
|
||||
initIncomingCall()
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@ObservedObject var tutorialContext = CallExampleContext()
|
||||
@ObservedObject var tutorialContext : CallExampleContext
|
||||
|
||||
func getCallButtonText() -> String
|
||||
{
|
||||
@@ -62,11 +62,21 @@ struct ContentView: View {
|
||||
.frame(width: 90.0, height: 42.0)
|
||||
.background(Color.gray)
|
||||
}
|
||||
Text("Login State : ")
|
||||
Spacer()
|
||||
Text("Login State :")
|
||||
.font(.footnote)
|
||||
Text(tutorialContext.loggedIn ? "Logged in" : "Unregistered")
|
||||
.font(.footnote)
|
||||
.foregroundColor(tutorialContext.loggedIn ? Color.green : Color.black)
|
||||
Spacer()
|
||||
Button(action: tutorialContext.clearRegistrations)
|
||||
{
|
||||
Text("Clear")
|
||||
.font(.largeTitle)
|
||||
.foregroundColor(Color.white)
|
||||
.frame(width: 90.0, height: 42.0)
|
||||
.background(Color.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
VStack(spacing: 0.0) {
|
||||
@@ -150,6 +160,6 @@ struct ContentView: View {
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
ContentView(tutorialContext: CallExampleContext())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
|
||||
|
||||
// Create the SwiftUI view that provides the window contents.
|
||||
let contentView = ContentView()
|
||||
|
||||
let delegate = UIApplication.shared.delegate as! AppDelegate
|
||||
|
||||
let contentView = ContentView(tutorialContext: delegate.tutorialContext)
|
||||
|
||||
// Use a UIHostingController as window root view controller.
|
||||
if let windowScene = scene as? UIWindowScene {
|
||||
let window = UIWindow(windowScene: windowScene)
|
||||
|
||||
Reference in New Issue
Block a user