2017-03-14 5 views
3

내 앱에서 SMS를 통해 알림을 보냅니다. 새보기 컨트롤러를 모달로 열려고하는데이 경우 경고가 전송되었습니다. 그러나 SMS를 보내거나 사용자가 취소 버튼을 클릭하면 messageComposeViewController가 닫히지 않고 중단됩니다. 엑스 코드 로그에messageComposeViewController 크래시를 신속하게 해결 3

오류는 다음과 같습니다

(lldb)

Crash

이 경고를 보내는 데 사용 내 코드입니다 :

엑스 코드 로그에서
import UIKit 
import CoreLocation 
import Social 
import MessageUI 
import BRYXBanner 

class AlertInProgressViewController: UIViewController, MFMessageComposeViewControllerDelegate, CLLocationManagerDelegate { 
[... Code here ...] 

func sms() 
    { 
     //Send sms 
     if(sms_exist()==true) 
     { 
      if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways) 

      { 

       locationManager.delegate = self 
       locationManager.desiredAccuracy = kCLLocationAccuracyBest 
       locationManager.requestWhenInUseAuthorization() 
       locationManager.startUpdatingLocation() 
       locationManager.startUpdatingHeading() 


       let mlocation = self.locationManager.location 

       if mlocation != nil { 

        let latitude: Double = mlocation!.coordinate.latitude 
        let longitude: Double = mlocation!.coordinate.longitude 
        let latitude_convert:String = String(format:"%f", latitude) 
        let longitude_convert:String = String(format:"%f", longitude) 
        let location = number_street + " " + ville + "\nLatitude " + latitude_convert + " - Longitude : " + longitude_convert 
        let geoCoder = CLGeocoder() 
        let location_details = CLLocation(latitude: mlocation!.coordinate.latitude, longitude: mlocation!.coordinate.longitude) 
        geoCoder.reverseGeocodeLocation(location_details) 
        { 
         (placemarks, error) -> Void in 

         let placeArray = placemarks as [CLPlacemark]! 

         // Place details 
         var placeMark: CLPlacemark! 
         placeMark = placeArray?[0] 

         // Address dictionary 
         print(placeMark.addressDictionary) 

         // Location name 
         if let locationName = placeMark.addressDictionary?["Name"] as? NSString 
         { 
          print(locationName) 
          self.details_location = locationName as String 
         } 
         if let city = placeMark.addressDictionary?["City"] as? NSString 
         { 
          self.city = city as String 
         } 

         self.message = NSLocalizedString("IN_DANGER_TEXT_SHARE",comment:"I'm in danger, I'm currently at ") + location + "\n - " + self.details_location + " - " + self.city 
         let defaults = UserDefaults.standard 
         let sms_perso = defaults.object(forKey: "sms") as? String 

        if(MFMessageComposeViewController.canSendText()) { 
          let controller = MFMessageComposeViewController() 
          controller.body = self.message 
          controller.recipients = [sms_perso!] 
          controller.messageComposeDelegate = self 
          self.present(controller, animated: true, completion: nil) 
         } 
         else 
         { 
          print("Can't send sms") 
         } 


        } 
       } 
      } 


     } 

    } 
[...] 
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) { 

     //Original code but doesn't work too 
     //self.dismiss(animated: true, completion: nil) 
     OperationQueue.main.addOperation { 
      self.dismiss(animated: true, completion: {}); 
     } 
     print("I want to dismiss here") 
    } 
} 

, 내가 볼 수 있습니다 : 나는 여기에서 기각하고 싶다. 그래서 messageComposeViewController가 호출되었지만 충돌 후.

AlertInProgressViewController를 표시하려면 스토리 보드 단락을 사용하십시오.

답변

1

나는 이것을 변경하여 내 문제를 해결 :

self.dismiss(animated: true, completion: {}); 

controller.dismiss(animated: true, completion: nil) 

에 의해