0

I used xcode 9.4 with swift 3 the code is working fine and its was in live. Now when i run my same code in xcode 10.1 i am getting many segmentation fault 11 error for many files.Not sure how can i do that.And how can i conver my swift 3 to swift 4. Bec many files i needs to change syntax.

Better i needs to use swift 3 in xcode 10.1 and needs to resolve that segmentation fault 11.

Major error i got in here :

  1. While emitting SIL for 'application(_:didReceiveRemoteNotification:)' at /Users/Documents/Rough/jeder/JEDE_r/AppDelegate.swift:258:5
  2. While silgen emitFunction SIL function "@$S3WCi11AppDelegateC11application_28didReceiveRemoteNotificationySo13UIApplicationC_SDys11AnyHashableVypGtF". for 'application(_:didReceiveRemoteNotification:)' at /Users/Documents/Rough/jeder/JEDE_r/AppDelegate.swift:258:5 error: Segmentation fault: 11

My code :

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) 
{
    if application.applicationState == .inactive || application.applicationState == .background {
        //opened from a push notification when the app was on background
    }
    else
    {
        if application.applicationState == .active
        {
            let myuserinfo = userInfo as NSDictionary
            print(myuserinfo)

            let tempDict:NSDictionary = (myuserinfo.value(forKey: "aps") as? NSDictionary)!
            let alert = UIAlertView(title: "alertView", message: (tempDict.value(forKey: "alert") as? String)!, delegate: nil, cancelButtonTitle:"Cancel", otherButtonTitles: "Done", "Delete")
            alert.show()
            let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary!)!
        }
    }
}

Whats the issues here. How can i get solve all the segmentation fault 11 error nearly 22 files its showing that error.

Any help on that please !!

david
  • 636
  • 2
  • 12
  • 29

2 Answers2

1

Change this line:

let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary!)!

to

let person:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary)!

Also in same appdelegate one more method also you doing like same. Replace that line with above one. Might be this help. Let me know or post any other issues if you got any.

spike04
  • 126
  • 2
-1

Please try below code

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])
    {
        if application.applicationState == .inactive || application.applicationState == .background {
            //opened from a push notification when the app was on background
        }
        else
        {
            if application.applicationState == .active
            {
                let myuserinfo = userInfo as NSDictionary
                print(myuserinfo)

                let tempDict:NSDictionary = ((myuserinfo.value(forKey: "aps") as? NSDictionary))!
                let alert = UIAlertController(title: "alertView", message: (tempDict.value(forKey: "alert") as? String)!, preferredStyle: .alert)
                let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
                alert.addAction(ok)
                //alert.show()
                self.window?.rootViewController?.present(alert, animated: true, completion: nil)
                let _:NSDictionary = (tempDict.value(forKey: "custom") as? NSDictionary)!
            }
        }
  }
Vijay Kahar
  • 1,082
  • 1
  • 7
  • 20