-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide the ability for use without UIKit #919
Conversation
Bugsnag/BugsnagSystemState.m
Outdated
@@ -189,27 +190,27 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)config { | |||
[weakSelf setValue:@NO forAppKey:SYSTEMSTATE_APP_IS_IN_FOREGROUND]; | |||
}]; | |||
#else | |||
[center addObserverForName:UIApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { | |||
[center addObserverForName:@"UIApplicationWillTerminateNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels dangerous, because any typo won't be detected. Could we instead define our own constants in one place, and then in the tests use a macro to check against the UIKit ones? e.g.
#define ASSERT_NOTIFICATION_NAME(name) XCTAssertEqualObjects(BSGUI ## name, UI ## name)
ASSERT_NOTIFICATION_NAME(ApplicationDidBecomeActiveNotification);
ASSERT_NOTIFICATION_NAME(ApplicationDidEnterBackgroundNotification);
Bugsnag/Client/BugsnagClient.m
Outdated
[UIDevice currentDevice].batteryMonitoringEnabled = NO; | ||
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; | ||
[NSClassFromString(@"UIDevice") currentDevice].batteryMonitoringEnabled = NO; | ||
[[NSClassFromString(@"UIDevice") currentDevice] endGeneratingDeviceOrientationNotifications]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is used in a bunch of places, can we have it as a utility function?
b65f344
to
30a1025
Compare
30a1025
to
407037a
Compare
407037a
to
b6bb174
Compare
Goal
Some types of app extensions have such severe memory limits (e.g. 30MB for a file provider extension) that linking UIKit is undesirable.
These changes make it possible to use Bugsnag without linking UIKit.
Design
The approach used here to avoid the use of any UIKit symbols - i.e. Objective-C classes, function names or symbols like NSNotification names.
We can still
#import <UIKit/UIKit.h>
because Clang's autolinking works on the basis of the symbols referenced by code.Note: this is contrary to the Quick Help Summary show in Xcode:
Even with
CLANG_MODULES_AUTOLINK = YES
(the default)otool -L
shows that removing the use of all UIKit symbols from our code also removes the linker dependency.We can also still send messages to UIKit objects in the normal way as this does not introduce any link-time dependencies.
Changeset
CLANG_MODULES_AUTOLINK
has been set toNO
in the top-level Bugsnag project - this will cause a build failure if we reintroduce a link-time dependency on UIKit e.g.Undefined symbol: _OBJC_CLASS_$_UIDevice
NSClassFromString()
to avoid linking against the class symbolTesting