我的应用程序在AppDelegate中停止。 我正在制作一个可以访问相机和照片库的应用程序,我可以在我的应用程序中上传照片。 我在Xcode的真实iPhone中运行我的应用程序,但是当我放入相机访问按钮&照片库按钮,我的应用程序停在AppDelegate.swift的一部分
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)
}
}
并且无法移动。 在Cornroller,我写了
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:.
}
}
和AppDelegate.swift就像
<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>
Info.plist就像
Thread 1:signal SIGABRT
错误消息类似于with open('/path/to/data','r') as f:
data = [line.strip() for line in f]
我用过TabBarController,就像
答案 0 :(得分:0)
您需要在info.plist
文件中提供照片和相机访问权限。
Privacy - Camera Usage Description
Privacy - Photo Library Usage Description
答案 1 :(得分:0)
我测试了你的代码,它很完美,代码中没有错误。
看来,你的故事板中的Interface Builder元素链接错误了。这种错误的原因是,故事板中的界面构建器与您的视图控制器的错误链接(附件)。
请检查您的初始故事板&amp;特别是初始视图控制器,它与连接检查器的连接&amp;身份检查员。
分享您最初的故事情节&amp;还可以使用身份检查器和连接检查器查看控制器。
编辑:根据您当前的快照,您可能已将Tabbar控制器用作初始视图控制器(并且已为共享的当前视图控制器传入两个连接。)但不包含有关tabbar的共享信息控制器在这里分享故事板的完整快照(和源代码)以获得准确的解决方案。
答案 2 :(得分:0)
关于iOS 10的以下答案只会影响应用程序的审核流程,并且会构建和运行而不会出现错误,因此在应用程序的工作能力方面添加这些内容将不会改变任何内容:
break
您遇到的问题通常是由于故事板的参考文献损坏。您可能更改了插座名称或IBAction方法。
您可以通过选择故事板中的视图控制器并在任何引用旁边查找Privacy - Camera Usage Description: purpose of your app using camera
Privacy - Photo Library Usage Description: purpose of your app using Photo
来检查此问题。如果有!
,请单击X以删除引用。
参见附图(查看向下箭头)
您还可以在代码中查找您的商店或操作旁边的空白圈。
答案 3 :(得分:-1)
从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