New delegates for carPlay - swift

I am devleoping navigation app for CarPlay and in iOS 12 there were two methods from CPApplicationDelegate to detect if CarPlay is on:
func application(_ application: UIApplication, didConnectCarInterfaceController interfaceController: CPInterfaceController, to window: CPWindow)
and
func application(_ application: UIApplication, didDisconnectCarInterfaceController interfaceController: CPInterfaceController, from window: CPWindow)
In iOS 13 these methods are deprecated and Apple gave new delegate: CPTemplateApplicationSceneDelegate
I have tried to connect this new delegate CPTemplateApplicationSceneDelegate to my service that provides all actions for CarPlay but only function I see that can help me is:
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
So my question is how to detect if CarPlay is connected and how to provide action for CarPlay launched in one window of new iOS 13 CarPlay.

---------------------------EDIT------------------------
In general target's settings check "Supports multiple windows". Then in Info.plist add configuration to your carPlay scene role (CPTemplateApplicationSceneSessionRoleApplication), like this:
And voilà!
Your delegate will invoke at
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController, to window: CPWindow)
where you can configure your CarPlay controller.
---------------------------END ------------------------
I will try something like this:
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if connectingSceneSession.role == UISceneSession.Role.carTemplateApplication {
if let carPlayScene = connectingSceneSession.scene as? CPTemplateApplicationScene {
carPlayScene.delegate = self
}
}
and then in your delegate's method you should setup your interface like in iOS12
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController, to window: CPWindow)
Don't know if it works, because my CarPlay simulator crashes...

Related

Identify application restart by camera and audio permission change swift

I have a video calling application now issue is that if the user declines the permission and once the user grants the camera access permission then the iOS application restarts then how I can know the application restart due to permission change?
Is there any method called from appdelegate before restart or after restart?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return orientationLock
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
}
func applicationDidEnterBackground(_ application: UIApplication) {
}
func applicationDidBecomeActive(_ application: UIApplication) {
}
func applicationWillTerminate(_ application: UIApplication) {
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
}

Thread 1: "-[UITableViewController loadView] loaded the \"Bf3-ih-lsC-view-YnG-aC-da7\" nib but didn't get a UITableView."

import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Model.shared.loadXMLFile(date: nil)
Model.shared.parseXML()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}
When you create a UITableViewController in your storyboard, its main view must be a UITableView. This error often happens when some other controller type is changed to a UITableViewController but with its old main view still in place.

Unexpected changes when running xcode project

When I try to build and run the project at first it looks ok (everything runs the way it should) but after a few seconds the screen disappears and a Hello World app (which I created a while ago) appears. This also happens with the other apps I've built, how can I stop the Hello World app from running? Once it appears I can’t change it back to the project I want to run, regardless of how many times I click the screen. I have even deleted the file and somehow it’s still occurring?
My ContentView.swift is:
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The App delegate:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}
Scene Delegate:
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
func sceneDidDisconnect(_ scene: UIScene) {
}
func sceneDidBecomeActive(_ scene: UIScene) {
}
func sceneWillResignActive(_ scene: UIScene) {
}
func sceneWillEnterForeground(_ scene: UIScene) {
}
func sceneDidEnterBackground(_ scene: UIScene) {
This is how it looks:

Facebook login + Firebase + Xcode 8 & Swift 3. ERROR

Xcode keeps complaining about an ambigous reference I've made in the AppDelegate. I'm trying to integrate Facebook Login with Firebase in my Xcode project using this tutorial.
Error:
Ambiguous reference to member
'application(_:didFinishLaunchingWithOptions:)'
Code:
import UIKit
import CoreData
import Firebase
import FBSDKLoginKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
private func application(_ app: UIApplication, open url: URL, options: UIApplicationOpenURLOptionsKey) -> Bool {
var handled = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) // Error happens here
// Add any custom logic here.
return handled
}
I'm not sure what what this error means (still new to iOS programming). I've highlighted where it happens in the code with a comment.
import UIKit
import Firebase
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, _: NSURL, sourceApplication: String, annotation: AnyObject) -> Bool {
let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
return handled
}

supportedInterfaceOrientationsForWindow in Swift 2.0

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Portrait.rawValue.hashValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue.hashValue
}
That used to work in Swift 1.2 however the return line is now throwing this error:
Binary operator '|' cannot be applied to two
'UIInterfaceOrientationMask' operands
I am able to get to work with just 1 return value with the new type but I cannot get it to pipe the second orientation I need.
This 'works'
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Portrait
}
But what I 'think' I need is this:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Portrait | UIInterfaceOrientationMask.PortraitUpsideDown
}
And it says the same error as I posted above.
Do you know how to properly set the orientation to 2 or more values in the in the AppDelegate in Swift 2.0?
Try new syntax:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
return [.Portrait, .PortraitUpsideDown]
}