iOS今天的扩展导致程序以退出代码结束:0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS今天的扩展导致程序以退出代码结束:0相关的知识,希望对你有一定的参考价值。
我正在使用Xcode 8.0,Swift 3。
我今天正在制作显示文字和图片的扩展程序,但经常导致此消息,今天扩展程序不起作用。很少工作。
程序以退出代码结束:0
我在领域保存数据,今天使用数据扩展(字符串,图像)
它是否会导致内存限制?所以,我怎样才能减少关于今天扩展的内存?
我的扩展代码:
class Information: Object {
dynamic var Name = ""
dynamic var Image : NSData?
override class func primaryKey() -> String {
return "Name"
}
}
class TodayViewController: UIViewController, NCWidgetProviding {
var realm : Realm?
var results : Results<Information>?
var index = 0
@IBOutlet var NameLabel: UILabel!
@IBOutlet var ImageView: UIImageView!
@IBAction func leftAction(_ sender: UIButton) {
guard index == 0 else {
index -= 1
loadData(index: index)
return
}
}
@IBAction func rightAction(_ sender: UIButton) {
guard index == (results?.count)! - 1 else {
index += 1
loadData(index: index)
return
}
}
override func viewDidLoad() {
super.viewDidLoad()
setRealmFileURL()
if #available(iosApplicationExtension 10.0, *) {
extensionContext?.widgetLargestAvailableDisplayMode = .expanded
}else{
preferredContentSize = CGSize(width: 0, height: 250)
}
// Do any additional setup after loading the view from its nib.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
realm = try! Realm()
results = try! Realm().objects(Information.self)
loadData(index: index)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
private func widgetPerformUpdate(completionHandler: ((NCUpdateResult) -> Void)) {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData
loadData(index: index)
completionHandler(NCUpdateResult.newData)
}
func loadData(index: Int){
guard results?.count == 0 else {
let objects = results?[index]
NameLabel.text = objects?.Name
ImageView.image = UIImage(data: (objects?.Image)! as Data, scale: 0.1)
return
}
}
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
preferredContentSize = CGSize(width: 0, height: 250)
}
func setRealmFileURL(){
var config = Realm.Configuration(encryptionKey: getKey() as Data)
let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.xxx")
let realmPath = directory?.appendingPathComponent("xxx.realm")
config.fileURL = realmPath
Realm.Configuration.defaultConfiguration = config
}
}
答案
除非应用程序中的某些内容需要更改,否则请勿使用
completionHandler(NCUpdateResult.NewData)
改为使用
completionHandler(NCUpdateResult.noData)
以上是关于iOS今天的扩展导致程序以退出代码结束:0的主要内容,如果未能解决你的问题,请参考以下文章
模拟器:进程以退出代码 -1073741515 (0xC0000135) 结束