Skip to content

Commit

Permalink
Merge pull request #72 from maicki/removeExtensionMacro
Browse files Browse the repository at this point in the history
Remove necessity of declaring PIN_APP_EXTENSIONS macro
  • Loading branch information
garrettmoon committed Mar 5, 2016
2 parents 4f37011 + 57ac3d9 commit 46d56ac
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 8 deletions.
45 changes: 37 additions & 8 deletions PINCache/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
static NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";

@interface PINBackgroundTask : NSObject
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
@property (atomic, assign) UIBackgroundTaskIdentifier taskID;
#endif
+ (instancetype)start;
Expand Down Expand Up @@ -1107,10 +1107,24 @@ - (void)unlock
@end

@implementation PINBackgroundTask

+ (BOOL)isAppExtension {

static BOOL isExtension;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
NSDictionary *extensionDictionary = [[NSBundle mainBundle] infoDictionary][@"NSExtension"];
isExtension = [extensionDictionary isKindOfClass:[NSDictionary class]];
});

return isExtension;
}

- (instancetype)init
{
if (self = [super init]) {
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
_taskID = UIBackgroundTaskInvalid;
#endif
}
Expand All @@ -1119,23 +1133,38 @@ - (instancetype)init

+ (instancetype)start
{
PINBackgroundTask *task = [[self alloc] init];
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
task.taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
PINBackgroundTask *task = nil;

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
if ([self.class isAppExtension]) {
return task;
}

task = [[self alloc] init];

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
task.taskID = [sharedApplication beginBackgroundTaskWithExpirationHandler:^{
UIBackgroundTaskIdentifier taskID = task.taskID;
task.taskID = UIBackgroundTaskInvalid;
[[UIApplication sharedApplication] endBackgroundTask:taskID];
[sharedApplication endBackgroundTask:taskID];
}];
#endif

return task;
}

- (void)end
{
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
if ([self.class isAppExtension]) {
return;
}

UIBackgroundTaskIdentifier taskID = self.taskID;
self.taskID = UIBackgroundTaskInvalid;
[[UIApplication sharedApplication] endBackgroundTask:taskID];

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
[sharedApplication endBackgroundTask:taskID];
#endif
}

Expand Down
159 changes: 159 additions & 0 deletions tests/PINCache.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
662900461A66B830009C10BD /* PINMemoryCache.h in Headers */ = {isa = PBXBuildFile; fileRef = D0E5D83E171DF0AF0041E777 /* PINMemoryCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
662900471A66B831009C10BD /* PINDiskCache.h in Headers */ = {isa = PBXBuildFile; fileRef = D0E5D83C171DF0AF0041E777 /* PINDiskCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
662900481A66B831009C10BD /* PINMemoryCache.h in Headers */ = {isa = PBXBuildFile; fileRef = D0E5D83E171DF0AF0041E777 /* PINMemoryCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
692C96731C88C37900CE9C49 /* ActionRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 692C96721C88C37900CE9C49 /* ActionRequestHandler.m */; };
692C96751C88C37900CE9C49 /* Action.js in Resources */ = {isa = PBXBuildFile; fileRef = 692C96741C88C37900CE9C49 /* Action.js */; };
692C96791C88C37900CE9C49 /* ShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 692C966F1C88C37900CE9C49 /* ShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
692C967F1C89D05A00CE9C49 /* PINDiskCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D0E5D83D171DF0AF0041E777 /* PINDiskCache.m */; };
692C96801C89D06100CE9C49 /* PINMemoryCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D0E5D83F171DF0AF0041E777 /* PINMemoryCache.m */; };
692C96811C89D06600CE9C49 /* PINCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D0E5D83B171DF0AF0041E777 /* PINCache.m */; };
D07F1EB6171AFB7A001DBA02 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1EB5171AFB7A001DBA02 /* UIKit.framework */; };
D07F1EB8171AFB7A001DBA02 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1EB7171AFB7A001DBA02 /* Foundation.framework */; };
D07F1EBA171AFB7A001DBA02 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1EB9171AFB7A001DBA02 /* CoreGraphics.framework */; };
Expand All @@ -40,6 +46,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
692C96771C88C37900CE9C49 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D07F1EAA171AFB7A001DBA02 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 692C966E1C88C37900CE9C49;
remoteInfo = ShareExtension;
};
D07F1ED7171AFB7A001DBA02 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D07F1EAA171AFB7A001DBA02 /* Project object */;
Expand All @@ -60,13 +73,29 @@
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
692C967D1C88C37900CE9C49 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
692C96791C88C37900CE9C49 /* ShareExtension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
662900111A66B60D009C10BD /* PINCache.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PINCache.framework; sourceTree = BUILT_PRODUCTS_DIR; };
662900141A66B60D009C10BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6629FFED1A66B512009C10BD /* PINCache.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PINCache.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6629FFF01A66B512009C10BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
692C966F1C88C37900CE9C49 /* ShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
692C96711C88C37900CE9C49 /* ActionRequestHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ActionRequestHandler.h; sourceTree = "<group>"; };
692C96721C88C37900CE9C49 /* ActionRequestHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ActionRequestHandler.m; sourceTree = "<group>"; };
692C96741C88C37900CE9C49 /* Action.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Action.js; sourceTree = "<group>"; };
692C96761C88C37900CE9C49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D07F1EB2171AFB7A001DBA02 /* PINCache.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PINCache.app; sourceTree = BUILT_PRODUCTS_DIR; };
D07F1EB5171AFB7A001DBA02 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
D07F1EB7171AFB7A001DBA02 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -107,6 +136,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
692C966C1C88C37900CE9C49 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
D07F1EAF171AFB7A001DBA02 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -161,6 +197,17 @@
name = "Supporting Files";
sourceTree = "<group>";
};
692C96701C88C37900CE9C49 /* ShareExtension */ = {
isa = PBXGroup;
children = (
692C96711C88C37900CE9C49 /* ActionRequestHandler.h */,
692C96721C88C37900CE9C49 /* ActionRequestHandler.m */,
692C96741C88C37900CE9C49 /* Action.js */,
692C96761C88C37900CE9C49 /* Info.plist */,
);
path = ShareExtension;
sourceTree = "<group>";
};
D07F1EA9171AFB7A001DBA02 = {
isa = PBXGroup;
children = (
Expand All @@ -170,6 +217,7 @@
D07F1EBC171AFB7A001DBA02 /* Supporting Files */,
6629FFEE1A66B512009C10BD /* iOS */,
662900121A66B60D009C10BD /* OS X */,
692C96701C88C37900CE9C49 /* ShareExtension */,
D07F1EB4171AFB7A001DBA02 /* Frameworks */,
D07F1EB3171AFB7A001DBA02 /* Products */,
);
Expand All @@ -182,6 +230,7 @@
D07F1ED2171AFB7A001DBA02 /* PINCacheTests.xctest */,
6629FFED1A66B512009C10BD /* PINCache.framework */,
662900111A66B60D009C10BD /* PINCache.framework */,
692C966F1C88C37900CE9C49 /* ShareExtension.appex */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -308,6 +357,23 @@
productReference = 6629FFED1A66B512009C10BD /* PINCache.framework */;
productType = "com.apple.product-type.framework";
};
692C966E1C88C37900CE9C49 /* ShareExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 692C967C1C88C37900CE9C49 /* Build configuration list for PBXNativeTarget "ShareExtension" */;
buildPhases = (
692C966B1C88C37900CE9C49 /* Sources */,
692C966C1C88C37900CE9C49 /* Frameworks */,
692C966D1C88C37900CE9C49 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = ShareExtension;
productName = ShareExtension;
productReference = 692C966F1C88C37900CE9C49 /* ShareExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
D07F1EB1171AFB7A001DBA02 /* PINCache */ = {
isa = PBXNativeTarget;
buildConfigurationList = D07F1EE4171AFB7A001DBA02 /* Build configuration list for PBXNativeTarget "PINCache" */;
Expand All @@ -316,10 +382,12 @@
D07F1EAF171AFB7A001DBA02 /* Frameworks */,
D07F1EB0171AFB7A001DBA02 /* Resources */,
6629002D1A66B60D009C10BD /* Embed Frameworks */,
692C967D1C88C37900CE9C49 /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
692C96781C88C37900CE9C49 /* PBXTargetDependency */,
);
name = PINCache;
productName = PINCache;
Expand Down Expand Up @@ -361,6 +429,9 @@
6629FFEC1A66B512009C10BD = {
CreatedOnToolsVersion = 6.1.1;
};
692C966E1C88C37900CE9C49 = {
CreatedOnToolsVersion = 7.2.1;
};
};
};
buildConfigurationList = D07F1EAD171AFB7A001DBA02 /* Build configuration list for PBXProject "PINCache" */;
Expand All @@ -379,6 +450,7 @@
D07F1ED1171AFB7A001DBA02 /* PINCacheTests */,
6629FFEC1A66B512009C10BD /* iOS */,
662900101A66B60D009C10BD /* OS X */,
692C966E1C88C37900CE9C49 /* ShareExtension */,
);
};
/* End PBXProject section */
Expand All @@ -398,6 +470,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
692C966D1C88C37900CE9C49 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
692C96751C88C37900CE9C49 /* Action.js in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D07F1EB0171AFB7A001DBA02 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -436,6 +516,17 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
692C966B1C88C37900CE9C49 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
692C96811C89D06600CE9C49 /* PINCache.m in Sources */,
692C96801C89D06100CE9C49 /* PINMemoryCache.m in Sources */,
692C967F1C89D05A00CE9C49 /* PINDiskCache.m in Sources */,
692C96731C88C37900CE9C49 /* ActionRequestHandler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D07F1EAE171AFB7A001DBA02 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -463,6 +554,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
692C96781C88C37900CE9C49 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 692C966E1C88C37900CE9C49 /* ShareExtension */;
targetProxy = 692C96771C88C37900CE9C49 /* PBXContainerItemProxy */;
};
D07F1ED8171AFB7A001DBA02 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = D07F1EB1171AFB7A001DBA02 /* PINCache */;
Expand Down Expand Up @@ -614,6 +710,61 @@
};
name = Release;
};
692C967A1C88C37900CE9C49 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pinterest.PINCache.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
692C967B1C88C37900CE9C49 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.pinterest.PINCache.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
D07F1EE2171AFB7A001DBA02 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -764,6 +915,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
692C967C1C88C37900CE9C49 /* Build configuration list for PBXNativeTarget "ShareExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
692C967A1C88C37900CE9C49 /* Debug */,
692C967B1C88C37900CE9C49 /* Release */,
);
defaultConfigurationIsVisible = 0;
};
D07F1EAD171AFB7A001DBA02 /* Build configuration list for PBXProject "PINCache" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
Loading

0 comments on commit 46d56ac

Please sign in to comment.