Ios 我的应用程序在AppDelegate中停止

Ios 我的应用程序在AppDelegate中停止,ios,iphone,swift,xcode,Ios,Iphone,Swift,Xcode,我的应用程序在AppDelegate中停止。 我正在制作一个可以访问相机和照片库的应用程序,我可以在我的应用程序中上传照片。 我从Xcode在真正的iPhone上运行我的应用程序,但当我按下相机访问按钮和照片库按钮时,我的应用程序在AppDelegate.swift部分停止 class AppDelegate: UIResponder, UIApplicationDelegate { 无法移动。 在玉米卷上,我写道 import UIKit class KenshinSendControll

我的应用程序在AppDelegate中停止。 我正在制作一个可以访问相机和照片库的应用程序,我可以在我的应用程序中上传照片。 我从Xcode在真正的iPhone上运行我的应用程序,但当我按下相机访问按钮和照片库按钮时,我的应用程序在AppDelegate.swift部分停止

class AppDelegate: UIResponder, UIApplicationDelegate {
无法移动。 在玉米卷上,我写道

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)
    }


}
身份检查员就像

而AppDelegate.swift就像

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:.
    }


}
plist就像

<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>
错误消息类似于线程1:信号SIGABRT 我用的是TabBarController,就像

连接检查器就像


您需要在info.plist文件中提供照片和相机访问权限

隐私-相机使用说明


隐私-照片库使用说明从iOS 10开始,您必须在info.plist文件中添加隐私说明,除非您的应用程序在请求权限时崩溃。在您的情况下,您必须添加:

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

我测试了你的代码,它是完美的,你的代码中没有错误

看起来,您在故事板中与Interface Builder元素的链接错误。出现这种错误的原因是,脚本中的interface builder与视图控制器的链接附件错误

请检查您的初始故事板&特别是初始视图控制器,以及连接检查器和标识检查器的附件

标识检查器:视图控制器是否与当前项目正确集成。 连接检查器:您没有任何错误的interface builder链接。 在此处与identity inspector和connection inspector共享您的初始storybaord&view控制器的快照


编辑:根据您当前的快照,您可能已经使用Tabbar控制器作为初始视图控制器,并且为您共享的当前视图控制器引入了两个连接。但此处未共享有关tabbar控制器的信息。共享故事板的完整快照和源代码,以获得准确的解决方案。

以下关于iOS 10的回答只会影响应用程序的审查过程,并且会生成并运行,不会出现错误,因此添加这些内容不会改变应用程序的工作能力:

Privacy - Camera Usage Description: purpose of your app using camera
Privacy - Photo Library Usage Description: purpose of your app using Photo
您遇到的问题通常是由于故事板中的引用中断造成的。您可能已更改了插座名称或IBAction方法

您可以通过在序列图像板中选择视图控制器并查找!在任何参考资料旁边。如果有!,单击X以删除引用

请参见附件中的“向下看”箭头

您还可以在代码中查找出口或操作旁边的空圆圈


共享错误消息可能会打印在控制台中。您的应用程序代理是默认的且正确的。thx您的评论,我添加我的信息。请共享此示例项目完整的源代码,将检查并用解决方案还原您。@KrunalBhavsar您认为哪种源代码?当前的源代码,您已添加到快照中,如果它不是机密的,并且您仍然面临问题。仅供参考,这里有一个链接可能有助于解释:thx,你的评论。但我已经做了。我应该怎么做才能修复它?thx,你的评论。但我已经做了。我应该怎么做才能修复它?