2017-03-04 3 views
-2

Meine App in AppDelegate stoppen. Ich mache eine App, die auf Kamera und Foto-Bibliothek zugreifen kann und ich kann Fotos in meiner App hochladen. Ich betreibe meine app in meinem realen iPhone von Xcode, aber wenn ich Zugriff auf die Kamera-Taste & Foto-Bibliothek-Taste gelegt, meine app in einem Teil gestoppt AppDelegate.swiftMeine App in AppDelegate stoppen

class AppDelegate: UIResponder, UIApplicationDelegate { 

und konnte sich nicht bewegen. In Cornroller schrieb ich

import UIKit 

class KenshinSendController:UIViewController, 
UINavigationControllerDelegate,UIImagePickerControllerDelegate{ 

    let ButtonCamera = 0 
    let ButtomRead = 1 
    let ButtonWrite = 2 

    var imageView:UIImageView = UIImageView() 
    var btnCamera:UIButton = UIButton(type: .custom) 
    var btnRead:UIButton = UIButton(type: .custom) 
    var btnWrite:UIButton = UIButton(type: .custom) 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     imageView.frame = CGRect(x: 150, y: 100, width: 200, height: 200) 
     imageView.contentMode = .scaleAspectFit 
     view.addSubview(imageView) 

     btnCamera.frame = CGRect(x: 0, y: 100, width: 100, height: 100) 
     btnCamera.setTitle("Camera", for: .normal) 
     btnCamera.tag = ButtonCamera 
     btnCamera.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside) 
     btnCamera.backgroundColor = UIColor.green 
     self.view.addSubview(btnCamera) 

     btnRead.frame = CGRect(x: 0, y: 200, width: 100, height: 100) 
     btnRead.setTitle("Read", for: .normal) 
     btnRead.tag = ButtomRead 
     btnRead.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside) 
     btnRead.backgroundColor = UIColor.red 
     self.view.addSubview(btnRead) 

     btnWrite.frame = CGRect(x: 0, y: 300, width: 100, height: 100) 
     btnWrite.setTitle("Write", for: .normal) 
     btnWrite.tag = ButtonWrite 
     btnWrite.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside) 
     btnWrite.backgroundColor = UIColor.blue 
     self.view.addSubview(btnWrite) 
    } 

    //ボタンクリック時に呼ばれる 
    @IBAction func ButtonCamera(_ sender: Any) { 
    } 
    @IBAction func ButtonRead(_ sender: Any) { 
    } 
    func onClick(sender:UIButton){ 
     if sender.tag == ButtonCamera { 
      openPicker(sourceType: UIImagePickerControllerSourceType.camera) 
     }else if sender.tag == ButtomRead { 
      openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary) 
     } 

    } 

    //アラートの表示 
    func showAlert(title: String?, text: String?) { 
     let alert = UIAlertController(title: title, message: text, preferredStyle: UIAlertControllerStyle.alert) 
     alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 
     present(alert, animated: true, completion: nil) 
    } 

    func openPicker(sourceType:UIImagePickerControllerSourceType){ 
     if !UIImagePickerController.isSourceTypeAvailable(sourceType){ 
      showAlert(title: nil, text: "利用できません") 
      return 
     } 

     let picker = UIImagePickerController() 
     picker.sourceType = sourceType 
     picker.delegate = self 

     present(picker, animated: true, completion: nil) 
      } 

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
     let image = info[UIImagePickerControllerOriginalImage]as! UIImage 
     imageView.image = image 

     picker.presentingViewController?.dismiss(animated: true,completion:nil) 
    } 

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 
     picker.presentingViewController?.dismiss(animated: true, completion: nil) 
    } 


} 

Identität Inspector ist wie enter image description here

und AppDelegate.swift ist wie

import UIKit 
import Alamofire 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 


    var window: UIWindow? 


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 
     return true 
    } 

    func applicationWillResignActive(_ application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(_ application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(_ application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(_ application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(_ application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 

Info.plist wie ist

<plist version="1.0"> 
<dict> 
    <key>UILaunchStoryboardName</key> 
    <string></string> 
    <key>CFBundleGetInfoString</key> 
    <string></string> 
    <key>NSPhotoLibraryUsageDescription</key> 
    <string>フォトライブラリの使用許可をお願いします</string> 
    <key>CFBundleDisplayName</key> 
    <string></string> 
    <key>NSCameraUsageDescription</key> 
    <string>カメラの使用許可をお願いします</string> 
    <key>LSApplicationCategoryType</key> 
    <string></string> 
    <key>CFBundleDevelopmentRegion</key> 
    <string>en</string> 
    <key>CFBundleExecutable</key> 
    <string>$(EXECUTABLE_NAME)</string> 
    <key>CFBundleIdentifier</key> 
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> 
    <key>CFBundleInfoDictionaryVersion</key> 
    <string>6.0</string> 
    <key>CFBundleName</key> 
    <string>$(PRODUCT_NAME)</string> 
    <key>CFBundlePackageType</key> 
    <string>APPL</string> 
    <key>CFBundleShortVersionString</key> 
    <string>1.0</string> 
    <key>CFBundleVersion</key> 
    <string>1</string> 
    <key>LSRequiresIPhoneOS</key> 
    <true/> 
    <key>UIMainStoryboardFile</key> 
    <string>Main</string> 
    <key>UIRequiredDeviceCapabilities</key> 
    <array> 
     <string>armv7</string> 
    </array> 
    <key>UISupportedInterfaceOrientations</key> 
    <array> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 
    <key>UISupportedInterfaceOrientations~ipad</key> 
    <array> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationPortraitUpsideDown</string> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 
</dict> 
</plist> 

Fehlermeldung ist wie Thread 1:signal SIGABRT I TabBarController verwendet wird, ist es wie enter image description here

Anschluss Inspector wie enter image description here

enter image description here

+1

Teilen Fehlermeldung (kann in der Konsole gedruckt werden). Ihr App-Delegat ist standardmäßig und korrekt. –

+0

thx ur kommentieren, ich füge meine Info hinzu. – user7523656

+0

Bitte teilen Sie dieses (Ihr) Beispielprojekt (vollständiger Quellcode), wird Sie mit Lösung überprüfen und wiederherstellen. – Krunal

Antwort

0

Sie Foto und Kamera benötigen, um Zugang in info.plist Datei.

Privacy - Camera Usage Description

Privacy - Photo Library Usage Description

+0

. FYI, hier ist ein Link, der erklären kann: https://useyourloaf.com/blog/privacy-settings-in-ios-10/ – dfd

+0

thx, ur comments.Aber ich tat es schon. Was soll ich tun, um es zu beheben? – user7523656

-1

Von iOS 10, haben Sie die Privatsphäre Beschreibungen in Ihrer info.plist Datei hinzuzufügen, es sei denn Ihre Anwendung, wenn Anfrage Erlaubnis zum Absturz. In Ihrem Fall müssen Sie hinzufügen:

Privacy - Camera Usage Description : purpose of your app using camera 
Privacy - Photo Library Usage Description : purpose of your app using Photo 
+0

thx, ur comments.Aber ich tat es schon. Was soll ich tun, um es zu beheben? – user7523656

0

Ich habe Ihren Code getestet, und es ist perfekt, es gibt keinen Fehler in Ihrem Code.

Es scheint, dass Sie eine falsche Verknüpfung mit Interface Builder in Ihrem Storyboard haben. Grund für diese Art von Fehler ist der falsche Link (Anhang) des Interface Builders im Storyboard mit Ihrem View-Controller.

Bitte überprüfen Sie Ihre ursprünglichen Storyboard & vor allem die erste Ansicht Controller, seine Anlage mit Verbindung Inspektor & Identity Inspector.

  • Identität Inspector: Ihr View-Controller ordnungsgemäß mit aktuellem Projekt integriert ist oder nicht.
  • Verbindung Inspektor: Sie haben keine falsche Verbindung von Interface Builder.

Share Sie Momentaufnahme Ihrer anfänglichen storybaord & View-Controller auch mit Identität Inspektor und Verbindungsinspektor.

Edit: Nach Ihrer aktuellen Momentaufnahme, können Sie Tabbar Controller als Anfang View-Controller verwendet haben, aber nicht hier Informationen über Tabbar Controller geteilt (und zwei Anschlüsse für Strom-View-Controller werden eingehende Sie freigegeben haben.). Teilen Sie den vollständigen Snapshot (und den Quellcode) Ihres Storyboards, um eine genaue Auflösung zu erhalten.

0

Die folgenden Antworten zu iOS 10 wirkt sich nur auf den Überprüfungsprozess der App und bauen und ohne Fehler ausgeführt, so dass diese Zugabe wird die Arbeit nichts in gewisser Hinsicht von der Fähigkeit der App ändern:

Privacy - Camera Usage Description: purpose of your app using camera 
Privacy - Photo Library Usage Description: purpose of your app using Photo 

Die Frage Du erlebst in der Regel aufgrund einer kaputten Referenz dein Storyboard. Sie haben möglicherweise einen Ausgangsnamen oder eine IBAction-Methode geändert.

Sie können dies überprüfen, indem Sie den View-Controller im Storyboard auswählen und neben allen Referenzen nach einem ! suchen. Wenn es eine ! gibt, klicken Sie auf das X, um die Referenz zu löschen.

angehängtes Bild sehen (siehe Pfeil unten)

enter image description here

Sie können auch neben Ihren Filialen oder Aktionen in dem Code für einen leeren Kreis suchen.

enter image description here