-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ExpoModulesCore | ||
|
||
internal class UrlDocumentDirectoryException: Exception { | ||
override var reason: String { | ||
"Unable to get url for document directory" | ||
} | ||
} | ||
|
||
internal class InstallationTimeException: Exception { | ||
override var reason: String { | ||
"Unable to get installation time of this application" | ||
} | ||
} | ||
|
||
internal class DateCastException: Exception { | ||
override var reason: String { | ||
"Invalid date format" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2018-present 650 Industries. All rights reserved. | ||
import ExpoModulesCore | ||
|
||
public class ApplicationModule: Module { | ||
public func definition() -> ModuleDefinition { | ||
Name("ExpoApplication") | ||
|
||
Constants { | ||
let infoPlist = Bundle.main.infoDictionary | ||
return [ | ||
"applicationName": infoPlist?["CFBundleDisplayName"], | ||
"applicationId": infoPlist?["CFBundleIdentifier"], | ||
"nativeApplicationVersion": infoPlist?["CFBundleShortVersionString"], | ||
"nativeBuildVersion": infoPlist?["CFBundleVersion"] | ||
] | ||
} | ||
|
||
AsyncFunction("getIosIdForVendorAsync") { () -> String? in | ||
return UIDevice.current.identifierForVendor?.uuidString | ||
} | ||
|
||
AsyncFunction("getInstallationTimeAsync") { () -> Double in | ||
guard let urlToDocumentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else { | ||
throw UrlDocumentDirectoryException() | ||
} | ||
|
||
do { | ||
let fileAttributes = try FileManager.default.attributesOfItem(atPath: urlToDocumentsFolder.path) | ||
if let installDate = fileAttributes[FileAttributeKey.creationDate] as? Date { | ||
return installDate.timeIntervalSince1970 * 1000 | ||
} | ||
throw DateCastException() | ||
} catch { | ||
throw InstallationTimeException() | ||
} | ||
} | ||
|
||
AsyncFunction("getApplicationReleaseTypeAsync") { () -> Int in | ||
let mainProvisioningProfile = ApplicationModuleProvisioningProfile.mainProvisioningProfile | ||
return mainProvisioningProfile.appReleaseType().rawValue | ||
} | ||
|
||
AsyncFunction("getPushNotificationServiceEnvironmentAsync") { () -> String? in | ||
let mainProvisioningProfile = ApplicationModuleProvisioningProfile.mainProvisioningProfile | ||
return mainProvisioningProfile.notificationServiceEnvironment() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2015-present 650 Industries. All rights reserved. | ||
import ExpoModulesCore | ||
|
||
class ApplicationModuleProvisioningProfile { | ||
private let plist = readProvisioningProfilePlist() | ||
static let mainProvisioningProfile = ApplicationModuleProvisioningProfile() | ||
|
||
func notificationServiceEnvironment() -> String? { | ||
guard let plist = plist else { | ||
return nil | ||
} | ||
|
||
let entitlements = plist["Entitlements"] as? [String: Any] | ||
return entitlements?["aps-environment"] as? String | ||
} | ||
|
||
func appReleaseType() -> AppReleaseType { | ||
guard let provisioningPath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else { | ||
#if targetEnvironment(simulator) | ||
return .simulator | ||
#else | ||
return .appStore | ||
#endif | ||
} | ||
|
||
guard let mobileProvision = plist else { | ||
return .unknown | ||
} | ||
|
||
if let provisionsAllDevices = mobileProvision["ProvisionsAllDevices"] as? Bool, provisionsAllDevices { | ||
return .enterprise | ||
} | ||
if let provisionedDevices = mobileProvision["ProvisionedDevices"] as? [String], !provisionedDevices.isEmpty { | ||
let entitlements = mobileProvision["Entitlements"] as? [String: Any] | ||
if let getTaskAllow = entitlements?["get-task-allow"] as? Bool, getTaskAllow { | ||
return .dev | ||
} | ||
return .adHoc | ||
} | ||
return .appStore | ||
} | ||
|
||
private static func readProvisioningProfilePlist() -> [String: Any]? { | ||
guard let profilePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else { | ||
return nil | ||
} | ||
|
||
do { | ||
let profileString = try String(contentsOfFile: profilePath, encoding: .ascii) | ||
guard let plistStart = profileString.range(of: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"), | ||
let plistEnd = profileString.range(of: "</plist>") else { | ||
return nil | ||
} | ||
|
||
let plistString = String(profileString[plistStart.lowerBound..<plistEnd.upperBound]) | ||
if let plistData = plistString.data(using: .utf8) { | ||
return try PropertyListSerialization.propertyList(from: plistData, options: [], format: nil) as? [String: Any] | ||
} | ||
log.error("Failed to convert plistString to UTF-8 encoded data object.") | ||
return nil | ||
} catch { | ||
log.error("Error reading provisioning profile: \(error.localizedDescription)") | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
enum AppReleaseType: Int, Enumerable { | ||
case unknown = 0 | ||
case simulator = 1 | ||
case enterprise = 2 | ||
case dev = 3 | ||
case adHoc = 4 | ||
case appStore = 5 | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.