-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enable App-Extension-Safe use of API's #669
Conversation
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.
Very interesting approach. I've added a few comments.
@@ -181,6 +187,7 @@ | |||
F522538D1CBE2F85002EECA9 /* SLKTypingIndicatorProtocol.h in Headers */, | |||
F52253951CBE2F85002EECA9 /* UIView+SLKAdditions.h in Headers */, | |||
F52253851CBE2F85002EECA9 /* SLKTextInputbar.h in Headers */, | |||
751FBFFA20B434480073DF8B /* UIApplication+ExtensionSafe.h in Headers */, |
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.
Why does this extension need to be public really?
|
||
@implementation UIApplication (ExtensionSafe) | ||
|
||
+ (BOOL)isAppExtension |
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 is unused and unexposed. Do we really need it?
UIApplication *safeSharedApplication = nil; | ||
|
||
if ([UIApplication respondsToSelector:@selector(sharedApplication)]) { | ||
safeSharedApplication = [UIApplication performSelector:@selector(sharedApplication)]; |
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.
Calling [UIApplication sharedApplication]
would be just simpler here, don't you think?
if ([UIApplication respondsToSelector:@selector(sharedApplication)]) { | ||
safeSharedApplication = [UIApplication performSelector:@selector(sharedApplication)]; | ||
} | ||
if (!safeSharedApplication.delegate) { |
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.
safeSharedApplication.delegate == nil
is preferrable
{ | ||
UIApplication *safeSharedApplication = nil; | ||
|
||
if ([UIApplication respondsToSelector:@selector(sharedApplication)]) { |
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.
All this logic should probably be executed once and only, by wrapping it in a static dispatch_once_t
.
PR Summary
Enables safe access of
UIApplication sharedApplication
when the framework is included in an application extension target.Related Issues
#670
Test strategy
Verify that project builds and has
Require Only App-Extension-Safe API
enabled.