5

I'm getting this crash on 9.3 update, on 9.2 everything worked fine. What can it be? The error appears on sign in through any source (login pass, VK, google)

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?

private let settingsManager = SettingsManager.manager

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

//  Googole Map
    GMSServices.provideAPIKey("-k")

    UINavigationBar.appearance().tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    UINavigationBar.appearance().barTintColor = #colorLiteral(red: 0.2069905996, green: 0.2386507988, blue: 0.3337202668, alpha: 1)

    UITabBar.appearance().tintColor = #colorLiteral(red: 0.2069905996, green: 0.2386507988, blue: 0.3337202668, alpha: 1)

    let barFont = UIFont.systemFont(ofSize: 20)
    UINavigationBar.appearance().titleTextAttributes =  [NSForegroundColorAttributeName: #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1), NSFontAttributeName: barFont]


    if settingsManager.isFirstStartApp {

    } else {

        settingsManager.isFirstStartApp = true
        settingsManager.setDefaultSettings()

    }

    // Facebook
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    // Google +
    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(String(describing: configureError)) )")
    GIDSignIn.sharedInstance().delegate = self

    return true
}

Error in the first application method when signing throug google. I've searched some topics - no luck. Conversion to Swift 4 - no luck. Any ideas?

Crash log pastebin.com/DEEeQnZB

With the accepted answer I got further, bbut now it crashes on

        let predicate = NSPredicate(format: "isActive == %@", true as CVarArg) 

with the same "Bad access"

UPD: The issue is resolved by replacing

let predicate = NSPredicate(format: "isActive == %@", true as CVarArg)

to

let predicate = NSPredicate(format: "isActive == true")
Max Kraev
  • 740
  • 12
  • 31

3 Answers3

15

Have a similar issue with Facebook login - a work for me was found in the Xcode 9.3 release notes:

https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-DontLinkElementID_1

To quote them

In circumstances where protocol methods or base class methods defined in Objective-C claim to take non-null arguments of type id in their headers, but get invoked with nil values at runtime, Swift code compiled by Xcode 9.3 that overrides those methods may crash when the Swift implementations are invoked. (38675815) Workaround: Change the Swift override to take a value of type Any?. For example, if you implement the UIApplicationDelegate protocol's application(_:open:sourceApplication:annotation:) method:

class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return true
}

The program may crash when passed nil as the annotation argument. Avoid the crash by making the annotation argument have type Any?:

class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
    return true
}
Spohn
  • 166
  • 1
  • 4
  • 1
    Well, I'm certainly got further, but now it crashes on "let predicate = NSPredicate(format: "isActive == %@", true as CVarArg) " with the same error – Max Kraev Apr 03 '18 at 11:21
  • Thank you! It works!! I had same problem when I use branch IO link with latest updated Xcode9.3. I am getting warning saying that "has different optionality than expected by protocol 'UIApplicationDelegate'" How can we make this warning silent? – Abhishek singh Apr 12 '18 at 06:43
  • @spohn Thank you! Works, but an having same problem as Abhishek – BriOnH Apr 19 '18 at 02:09
4

The crash is because of change in Xcode 9.3 swift compilation for ojective -c protocol base methods. So if the crash on app start in AppDelegate.swift file change the following function

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

to

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any?) -> Bool {

So basically you have to add ? after Any

Note Most important point:- You also have to remove the all Exception from the Show the Breakpoint navigator

enter image description here

Jitendra Gaur
  • 778
  • 4
  • 16
4

The below change fixed my NSPredicate issue.

from:

NSPredicate(format: "%K = %@", #keyPath(PlayerMO.isSelected), true as CVarArg)

to:

NSPredicate(format: "%K = %@", #keyPath(PlayerMO.isSelected), NSNumber(value: true))

Found the answer here: How to write a BOOL predicate in Core Data?

Luke
  • 71
  • 3