iOS App Extension with xib instead of storyboard

2019-03-13 16:31发布

问题:

I'm writing an iOS 8 App Extension (widget) for the Today view. The default template in xcode comes with a storyboard. How can I use an xib file instead of an storyboard?

The documentation says this is possible, but I can't seem to figure out how to change the info.plist file to get the xib loaded.

回答1:

all you need to do is add "NSExtensionPrincipalClass" and the classname which you want.



回答2:

As I recently discovered the hard way - notice that the 'NSExtensionPrincipalClass' must be directly under the 'NSExtension' key. e.g class ShareViewController:

<key>NSExtension</key>
<dict>
    <key>NSExtensionPrincipalClass</key>
    <string>ShareViewController</string>
    ...
</dict>


回答3:

By default, the Today template supplies the following Info.plist keys and values (shown here for an OS X target):

<key>NSExtension</key>
<dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.widget-extension</string>
    <key>NSExtensionPrincipalClass</key>
    <string>TodayViewController</string>
</dict>

If you use a custom view controller subclass, use the custom class name to replace the TodayViewController value for the NSExtensionPrincipalClass key.

iOS. If you don’t want to use the storyboard file provided by the template, remove the NSExtensionMainStoryboard key and add the NSExtensionPrincipalClass key, using the name of your view controller for the value.

Most of the work you do to create a Today widget involves designing the UI and implementing a view controller subclass that performs your custom functionality.

BY APPLE GUIDELINES:-->click to view