Today Extension example fails with EXC_BAD_ACCESS
If there is no issue for your problem, tell us about it
I am trying to follow along with the Today extension example discussed here: https://www.nativescript.org/blog/making-a-today-widget-in-ios-with-nativescript-and-ui-for-nativescript
Which has example code from this repository here: https://github.com/NativeScript/ios-runtime/tree/master/examples/TodayExtension
Trying to to complete this example results in a runtime error when trying to launch the TodayWidget extension directly from Xcode:
at runtime = [[TNSRuntime alloc] initWithApplicationPath:[NSBundle mainBundle].bundlePath];
in platforms/ios/TodayWidget/main.m
EXC_BAD_ACCESS
I found this old issue of a user with the same problem: https://github.com/NativeScript/ios-runtime/issues/503
An answer was posted in an old ios-runtime-docs repo which no longer exists so I cannot see what the fix for the problem was.
All in all, it seems like docs for iOS app extension support are not very complete or very outdated which is unfortunate since we need support for extensions to be able to switch to NativeScript from Xamarin. Perhaps some additional guidance or updated documentation could also be provided for using app extensions with NativeScript?
Please, provide the following version numbers that your issue occurs with:
- CLI: 4.0.2
- Cross-platform modules: 4.0.1
- Runtime(s): 4.0.1
- Plugin(s): n/a
Please, tell us how to recreate the issue in as much detail as possible.
Follow the tutorial at https://www.nativescript.org/blog/making-a-today-widget-in-ios-with-nativescript-and-ui-for-nativescript to add an app extension to the HelloWorld app. Then try to launch the extension from Xcode.
I'm also looking for up-to-date documentation for how to add different types of app extensions to an iOS app.
Did anyone find some news? I am also looking for this.
Nope. Still waiting for a response from the Nativescript team.
Hello @kspearrin
I just walked through the article and got the same error. After adding the ios runtime project to the widget's .xcodeproj so I can have the debug symbols, I saw the problem was missing metadata. So there are couple more things you need to do in order to run the widget:
-
Add these flags to Settings->Other Linker Flags:
-sectcreate __DATA __TNSMetadata "$(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin" $(inherited) -
Make the runtime aware of the metadata by adding the following two lines of code before allocating it
extern char startOfMetadataSection __asm("section$start$__DATA$__TNSMetadata");
[TNSRuntime initializeMetadata:&startOfMetadataSection];
so your main.m looks like this:
#import <NativeScript/NativeScript.h>
static TNSRuntime* runtime;
__attribute__((constructor))
void initialize() {
extern char startOfMetadataSection __asm("section$start$__DATA$__TNSMetadata");
[TNSRuntime initializeMetadata:&startOfMetadataSection];
runtime = [[TNSRuntime alloc] initWithApplicationPath:[NSBundle mainBundle].bundlePath];
TNSRuntimeInspector.logsToSystemConsole = YES;
[runtime executeModule:@"./tiobe-widget"];
}
P.S. The article and docs will be updated.
Thanks @tdermendjiev . That fixed it! Do the linker flags only need to be set for debug, or release too?
Also, it is not clear to me how these xcodeproj adjustments are suppose to be persisted since the nativescript /platforms directory is transient/generated and will be overwritten the next time the project is rebuilt.
The linker flags need to be set for release as well. Currently these settings are not supported out of Xcode which means they will be overridden. I will research what is needed to implement Today extensions support meanwhile you can vote for this feature. Thank you!
The current solution is far from perfect and requires quite a lot of manual changes. If you follow the updated steps in the tutorial, however, it does work.
That said, we've logged a new issue for app extensions support: NativeScript/nativescript-cli#3965. It is still not planned for implementation but at least can be voted for.
We would definitely welcome any contributions that can help us reach there!