Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Today Extension has a title, but no body iOS 8

I am trying out the new TodayExtensions in iOS 8 and I followed the steps to create a Today Extension as described in the WWDC video Creating Extensions for iOS and OS X, Part 1. I added a colored UIView to the ViewController in the provided storyboard. I get a title in my "Today" Notification center, but I get no body with my colored view. It looks like this (I made two):

enter image description here

Is anyone else getting this? I set breakpoints in all of my ViewControllers methods and nothing gets called. I changed my Info.plist to just go directly to my VC class, instead of the storyboard and I get nothing still. I can change the title of the today extension in the info.plist.

like image 529
SirRupertIII Avatar asked Jun 09 '14 20:06

SirRupertIII


4 Answers

First, to test that anything is happening, add awakeFromNib to your view controller and set preferred content size (all code in Obj C):

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setPreferredContentSize:CGSizeMake(self.view.bounds.size.width, 50)];
}

As milesper said above, comment out the default init method and create an empty initWithCoder: to get around some bug in Beta 2:

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // init
    }
    return self;
}

//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        // Custom initialization
//    }
//    return self;
//}

Now Clean and then run again. At this point you should see it resize (make sure you add a label with text or something to test).

Make sure you test with a plain UIViewController class, not a subclass. Once you see your widget size respond, then try a subclass. I spent an hour today just to find out that using UICollectionViewController simply doesn't work in Beta 2 (will file a RADAR).

like image 173
Alex the Ukrainian Avatar answered Nov 09 '22 19:11

Alex the Ukrainian


If you are running the app scheme and not the widget scheme, first thing to check will be the Device log or the Simulator log. As the Today's view is part of the system and not part of the app that you are debugging in Xcode, you won't see errors on the widget view controller on the Xcode's console. You can check the simulator's console on the System Log:

Simulator's log

If there was a crash on the widget view controller it will show something like this:

xxxxx.local Widget[43414]: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[TodayViewController 0x7fd893d7ca60> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'

If you select the widget target instead, xcode will attach the debugger to the today's view widget and if you have the 'All exceptions' breakpoint' enabled, you'll be able to see if there is an exception and where is being rised.

Widget target

like image 35
pablobart Avatar answered Nov 09 '22 18:11

pablobart


Comment out the original init method:

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

Add this init method:

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

Clean and Build your project. Make sure your widget content has a height constraint.

like image 2
mginn Avatar answered Nov 09 '22 20:11

mginn


I struggled a bit with this.

Then I figured out that it was trying to infer the height of the View using the Constraints for all subviews within the MainInterface.storyboard.

If you add all the necessary constraints to your view's subviews then the height of the Today Extension can be inferred and your view will appear as you intend.

like image 1
Seoras Avatar answered Nov 09 '22 18:11

Seoras