iOS 8 Beta Today extension widget not showing in a Swift app?

后端 未结 4 2089
难免孤独
难免孤独 2020-12-16 12:11

Today extension doesn\'t show up in a Swift app, but it does in a Objective C app.

What I did was to add a UILabel with some content on the storyboard for the swift

4条回答
  •  盖世英雄少女心
    2020-12-16 12:56

    You can comment out the supplied init method.

    //    init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    //        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    //        // Custom initialization
    //    }
    

    This will allow your extension to run properly. The issue seems to be caused by differing initializer behavior between Swift and Objective-C. Removing the above initializer will inherit all of the required initializers from the superclass.

    Found that solution on the apple developer forums for your reference.

    Note: You may have to Clean and Build your project after doing this before the changes will have any effect

    The extension is actually crashing, with an error like:

    fatal error: use of unimplemented initializer 'init(coder:)' for class 'com_blabla_blabla_MyTodayExtension.TodayViewController'
    

    This indicates that another option would be to implement:

    init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
        // Custom initialization here
    }
    

    if you want to retain the ability to do custom initialization.

提交回复
热议问题