Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Enable App-Extension-Safe use of API's #669

Closed
wants to merge 2 commits into from
Closed

Enable App-Extension-Safe use of API's #669

wants to merge 2 commits into from

Conversation

OskarGroth
Copy link

@OskarGroth OskarGroth commented May 22, 2018

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've been mindful about doing atomic commits, adding documentation to my changes, not refactoring too much.
  • I've added a descriptive title and added any useful information for the reviewer. Where appropriate, I've attached a screenshot and/or screencast (gif preferrably).
  • I've listed my changes on the [Changelog(https://github.com/slackhq/SlackTextViewController/blob/master/CHANGELOG.md) file.
  • I've read, agree to, and signed the Contributor License Agreement (CLA).

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.

Copy link

@dzenbot dzenbot left a 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 */,
Copy link

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
Copy link

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)];
Copy link

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) {
Copy link

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)]) {
Copy link

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.

@Dooer Dooer closed this by deleting the head repository Feb 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants