2016-10-26 4 views
7

मैं Xcode 8.0 उपयोग कर रहा हूँ, स्विफ्ट 3.आईओएस आज विस्तार कार्यक्रम बाहर निकलने के कोड के साथ समाप्त हो का कारण बनता है: 0

मैं पाठ और छवि दिखा आज विस्तार कर रही हूँ, लेकिन अक्सर इस संदेश का कारण है और आज विस्तार से काम नहीं करता । शायद ही कभी काम करते हैं।

कार्यक्रम बाहर निकलने के कोड के साथ समाप्त हुआ: 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 

    } 
} 

उत्तर

1

ज्यादातर यह स्मृति के साथ एक समस्या है। अगर यह ज्यादा उपभोग करता है तो विजेट काट दिया जाएगा।

+0

कितने स्मृति विजेट एक्सटेंशन ले सकता है का उपयोग करें? कम बेहतर है मुझे पता है लेकिन मेरे आईपैड प्रो पर आखिरी जीन पर मैं वर्तमान में 25 एमबी का उपयोग करता हूं और विजेट बंद तुरंत काम करता है। –

0

जब तक अनुप्रयोग में कुछ बदलने की जरूरत है, का उपयोग नहीं करते

completionHandler(NCUpdateResult.NewData) 

बजाय

completionHandler(NCUpdateResult.noData) 
संबंधित मुद्दे