iOS Today Extension created as .app rather than .a

2019-05-30 06:26发布

I'm trying to add a Today Extension to a project I've been working on for quite some time. In fact the app is in the AppStore already and I'm looking to enhance it with a Today Extension.

The problem is that the Extension won't launch at all. Not on the device nor on the simulator.

EDIT: just skip the next sections and read on at the last EDIT as I think I found the problem. I just not sure how to fix it.

I've done a test project following a tutorial and it works just fine. The environment seem(!) to be identical. Xcode 6.1.1, iOS 8.1 on the device and simulator.

My project is Objective-C based. For the Extension I’ve tried both Objective-C and Swift targets. On both occasions all three (four with obj-C) files were created as expected (storyboard, viewController and PLIST).

Having done nothing more (as with the example project) I'm trying to launch the widget with the widget scheme selected. With the test projects the widget would launch while it won't with the actual project.

I put a println()/NSLog in the viewDidLoad of the widgets viewController to see if anything happens but nothing.

Happy to provide code or settings but at this pointing time I've no idea where to start.

I just realised that with the test project the today view would launch/appear automatically when the widget gets run from Xcode. With my actual project I'm just getting the HomeScreen and have to pull down the Today view myself. So, really nothing at all happens regarding the widget while everything looks identical compared to the test project.

Any help is appreciated.

EDIT: Here is something I came across which might constitute the problem. The widget never gets launched really and gets stuck at ´Waiting to Attach´ in Xcode's Debug navigator. While other seemed to have had the same problem all potential solutions I found so far did't work for me.

EDIT: I noticed that when I add a Today widget as a target the binary is named .app. All test projects I did the binary gets created as .appex. All the information on the web suggests that it should be named .appex really. Where does this come from and how do I alter this?

3条回答
在下西门庆
2楼-- · 2019-05-30 07:13

Same problem happened today when I created a Notification Content extension in an old project.(2016, Xcode8 iOS10)

Finally I found the cause:

"Wrapper Extension" in Build Settings of the project was “app”, and when the new target of extension was created, "Wrapper Extension” inherited from the project settings as “app”.

Clearing the project setting before adding an extention target will make Xcode creat an extention as “appex” automatically.

查看更多
3楼-- · 2019-05-30 07:19

I am herewith sharing the step and source code.

Step 1:- App extension must have a containing app - you can't just create an app extension to be downloaded from the store, first create a regular app to contain the app extension. For the sake of this demonstration just create a new single view project and leave it untouched. Go to File-> New-> Project and select Single view application under iOS -> Applications call it 'ExtendableApp'.

Step 2:- If you want to create your custom experience simply set your ExtensionViewController to inherit from UIViewController, Once your extension is activated all the regular viewDidLoad, viewDidAppear, etc will be called.

Step 3:- In your controller storyboard create outlets for button, I am herewith describing 3 buttons.

Step 4:- In ExtensionViewController.m write

- (void)viewDidLoad {
    [super viewDidLoad];
    self.preferredContentSize = CGSizeMake(self.view.frame.size.width, 60.0f);
    // Do any additional setup after loading the view from its nib.
}

Step 5:- I am assuming that you have set the outlets and IB Action of your buttons in extension storyboard

- (IBAction) mActionButtonTapped :(UIButton *) sender {
    switch (sender.tag) {
        case 0: {
            NSURL *url = [NSURL URLWithString:@"IDENTIFIER_1://"];
            [self.extensionContext openURL:url completionHandler:nil];
        }
            break;
        case 1: {
            NSURL *url = [NSURL URLWithString:@"IDENTIFIER_2://"];
            [self.extensionContext openURL:url completionHandler:nil];
        }
            break;
        case 2: {
            NSURL *url = [NSURL URLWithString:@"IDENTIFIER_3://"];
            [self.extensionContext openURL:url completionHandler:nil];
        }
            break;

        default:
            break;
    }
}

Step 6:- In your project write these code in appDelete.m

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    [self appExtensionCallBack:url.absoluteString];
    return YES;
}

- (void) appExtensionCallBack :(NSString *)urlString {
    if ([urlString isEqualToString:@"IDENTIFIER_1://"]) {

            [self.tabBarController setSelectedIndex:0];   
    } else if ([urlString isEqualToString:@"IDENTIFIER_2://"]) {

            [self.tabBarController setSelectedIndex:1];
    } else if ([urlString isEqualToString:@"IDENTIFIER_3://"]) {

            [self.tabBarController setSelectedIndex:2];
    }
}

Note :- I am using Tab Bar Controller in my project, You can give own respected controller.

- (void) moveToControllerScene {
        UIStoryboard *storyboard              = [UIStoryboard storyboardWithName:STORY_BOARD_IDENTIFIER bundle:nil];
        YOUR_CONTROLLER_OBJECT *obj           = [storyboard instantiateViewControllerWithIdentifier:@"YOUR_CONTROLLER_OBJECT"];
        [navController pushViewController:obj animated:YES];
}

Step 7:- For testing the Extension in real device you have to make a separate App ID and Provisioning profile. Delete appropriate provisioning profile in extension and ur project.

查看更多
【Aperson】
4楼-- · 2019-05-30 07:22

I had the same problem.

The following steps helped:

selected target Today Extortion -> Build Settings -> line Wrapper Extension add (change) value to appex

See:

http://i.stack.imgur.com/zH7i7.png

查看更多
登录 后发表回答