Skip to content

Commit

Permalink
[expo-application][ios] Post-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Jan 16, 2020
1 parent 4cc7570 commit 8d66cc5
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 93 deletions.
4 changes: 2 additions & 2 deletions apps/test-suite/tests/Application.js
Expand Up @@ -52,8 +52,8 @@ export async function test({ describe, it, expect, jasmine }) {
expect(error).toBeNull();
});

it('Application.getIosAppReleaseType() returns a number', async () => {
const appReleaseType = await Application.getIosAppReleaseTypeAsync();
it('Application.getIosApplicationReleaseTypeAsync() returns a number', async () => {
const appReleaseType = await Application.getIosApplicationReleaseTypeAsync();
expect(appReleaseType).toBeDefined();
expect(appReleaseType).toEqual(jasmine.any(Number));
});
Expand Down
6 changes: 6 additions & 0 deletions ios/Exponent.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 2 additions & 34 deletions ios/Exponent/Kernel/AppLoader/EXFileDownloader.m
Expand Up @@ -6,9 +6,7 @@
#import "EXSession.h"
#import "EXVersions.h"
#import "EXKernelUtil.h"
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
#import <EXApplication/EXProvisioningProfile.h>
#endif
#import "EXClientReleaseType.h"

#import <React/RCTUtils.h>

Expand Down Expand Up @@ -109,44 +107,14 @@ - (void)setHTTPHeaderFields:(NSMutableURLRequest *)request
[request setValue:@"application/expo+json,application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"1" forHTTPHeaderField:@"Expo-Api-Version"];
[request setValue:clientEnvironment forHTTPHeaderField:@"Expo-Client-Environment"];
[request setValue:[self clientReleaseType] forHTTPHeaderField:@"Expo-Client-Release-Type"];
[request setValue:[EXClientReleaseType clientReleaseType] forHTTPHeaderField:@"Expo-Client-Release-Type"];

NSString *sessionSecret = [[EXSession sharedInstance] sessionSecret];
if (sessionSecret) {
[request setValue:sessionSecret forHTTPHeaderField:@"Expo-Session"];
}
}

- (NSString *)clientReleaseType
{
// The only scenario where we care about clientReleaseType is:
// - run on a real device
// - Expo client app
// - downloaded from App Store
// to determine whether the build is restricted. The file
// will always be available in Expo client, so that's good.
// In other scenarios we can fallback to "UNKNOWN".
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
EXAppReleaseType releaseType = [[EXProvisioningProfile mainProvisioningProfile] appReleaseType];
switch (releaseType) {
case EXAppReleaseTypeUnknown:
return @"UNKNOWN";
case EXAppReleaseSimulator:
return @"SIMULATOR";
case EXAppReleaseEnterprise:
return @"ENTERPRISE";
case EXAppReleaseDev:
return @"DEVELOPMENT";
case EXAppReleaseAdHoc:
return @"ADHOC";
case EXAppReleaseAppStore:
return @"APPLE_APP_STORE";
}
#else
return @"UNKNOWN";
#endif
}

- (NSString *)_userAgentString
{
struct utsname systemInfo;
Expand Down
31 changes: 2 additions & 29 deletions ios/Exponent/Kernel/DevSupport/EXHomeModule.m
Expand Up @@ -4,9 +4,7 @@
#import "EXHomeModule.h"
#import "EXSession.h"
#import "EXUnversioned.h"
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
#import <EXApplication/EXProvisioningProfile.h>
#endif
#import "EXClientReleaseType.h"

#import <React/RCTEventDispatcher.h>

Expand Down Expand Up @@ -43,32 +41,7 @@ + (BOOL)requiresMainQueueSetup
- (NSDictionary *)constantsToExport
{
return @{ @"sdkVersions": _sdkVersions,
@"IOSClientReleaseType": [self clientReleaseType] ?: [NSNull null] };
}

- (NSString *)clientReleaseType
{
// Presence of this file is assured in Expo client
// and in ejected projects HomeModule shouldn't ever be used.
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
EXAppReleaseType releaseType = [[EXProvisioningProfile mainProvisioningProfile] appReleaseType];
switch (releaseType) {
case EXAppReleaseTypeUnknown:
return @"UNKNOWN";
case EXAppReleaseSimulator:
return @"SIMULATOR";
case EXAppReleaseEnterprise:
return @"ENTERPRISE";
case EXAppReleaseDev:
return @"DEVELOPMENT";
case EXAppReleaseAdHoc:
return @"ADHOC";
case EXAppReleaseAppStore:
return @"APPLE_APP_STORE";
}
#else
return nil;
#endif
@"IOSClientReleaseType": [EXClientReleaseType clientReleaseType] ?: [NSNull null] };
}

#pragma mark - RCTEventEmitter methods
Expand Down
13 changes: 13 additions & 0 deletions ios/Exponent/Kernel/Environment/EXClientReleaseType.h
@@ -0,0 +1,13 @@
// Copyright 2015-present 650 Industries. All rights reserved.

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface EXClientReleaseType : NSObject

+ (NSString *)clientReleaseType;

@end

NS_ASSUME_NONNULL_END
41 changes: 41 additions & 0 deletions ios/Exponent/Kernel/Environment/EXClientReleaseType.m
@@ -0,0 +1,41 @@
// Copyright 2015-present 650 Industries. All rights reserved.

#import "EXClientReleaseType.h"
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
#import <EXApplication/EXProvisioningProfile.h>
#endif

@implementation EXClientReleaseType

+ (NSString *)clientReleaseType
{
// The only scenario in which we care about the app release type is when the App Store release of
// the Expo development client is run on a real device so the development client knows to restrict
// projects it can run. We always include expo-application in the App Store release of the
// development client, so we correctly return "APPLE_APP_STORE" in the aforementioned scenario.
//
// In all other scenarios, we don't restrict the projects the client can run and can return either
// the actual release type or "UNKNOWN" for the same behavior, so it doesn't matter whether
// expo-application is linked.
#if __has_include(<EXApplication/EXProvisioningProfile.h>)
EXAppReleaseType releaseType = [[EXProvisioningProfile mainProvisioningProfile] appReleaseType];
switch (releaseType) {
case EXAppReleaseTypeUnknown:
return @"UNKNOWN";
case EXAppReleaseSimulator:
return @"SIMULATOR";
case EXAppReleaseEnterprise:
return @"ENTERPRISE";
case EXAppReleaseDev:
return @"DEVELOPMENT";
case EXAppReleaseAdHoc:
return @"ADHOC";
case EXAppReleaseAppStore:
return @"APPLE_APP_STORE";
}
#else
return @"UNKNOWN";
#endif
}

@end
8 changes: 4 additions & 4 deletions packages/expo-application/build/Application.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions packages/expo-application/build/Application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d66cc5

Please sign in to comment.