Skip to content

Commit c18f2e1

Browse files
Add a utility to detect App Clips and make a semantic check for background URL sessions (#220)
1 parent 18c852e commit c18f2e1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

GoogleUtilities/Environment/GULAppEnvironmentUtil.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ + (BOOL)isAppExtension {
217217
#endif
218218
}
219219

220+
+ (BOOL)isAppClip {
221+
#if TARGET_OS_IOS
222+
// Documented by <a
223+
// href="https://developer.apple.com/documentation/bundleresources/information-property-list/nsappclip">Apple</a>
224+
// App clips have an NSAppClip entry in the top level of their Info.plist.
225+
NSDictionary *appClipEntry = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSAppClip"];
226+
return appClipEntry != nil;
227+
#elif TARGET_OS_OSX || TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION
228+
return NO;
229+
#endif
230+
}
231+
232+
+ (BOOL)supportsBackgroundURLSessionUploads {
233+
// Neither app extensions nor App Clips support background uploads.
234+
BOOL isExtension = self.isAppExtension;
235+
BOOL isAppClip = self.isAppClip;
236+
return !(isExtension || isAppClip);
237+
}
238+
220239
+ (NSString *)applePlatform {
221240
NSString *applePlatform = @"unknown";
222241

GoogleUtilities/Environment/Public/GoogleUtilities/GULAppEnvironmentUtil.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ NS_ASSUME_NONNULL_BEGIN
4646
/// Indicates whether it is running inside an extension or an app.
4747
+ (BOOL)isAppExtension;
4848

49+
/// Indicates whether it is running inside an app clip or a full app.
50+
+ (BOOL)isAppClip;
51+
52+
/// Indicates whether the current target supports background URL session uploads.
53+
/// App extensions and app clips do not support background URL sessions.
54+
+ (BOOL)supportsBackgroundURLSessionUploads;
55+
4956
/// @return An Apple platform. Possible values "ios", "tvos", "macos", "watchos", "maccatalyst", and
5057
/// "visionos".
5158
+ (NSString *)applePlatform;

0 commit comments

Comments
 (0)