-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite certificate check module to be more detailed
- Loading branch information
Showing
16 changed files
with
127 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"platforms": ["ios"], | ||
"ios": { | ||
"modules": ["CheckIosAppIdModule"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import CheckIosAppIdModule from "./src/CheckIosAppIdModule"; | ||
|
||
export function isIncorrectAppId(): boolean { | ||
return CheckIosAppIdModule.isIncorrectAppId(); | ||
} | ||
|
||
export function getAppId(): string { | ||
return CheckIosAppIdModule.getAppId(); | ||
} |
6 changes: 3 additions & 3 deletions
6
...rtificate/ios/CheckIosCertificate.podspec → ...heck-ios-app-id/ios/CheckIosAppId.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
apps/expo/modules/check-ios-app-id/ios/CheckIosAppIdModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import ExpoModulesCore | ||
|
||
public class CheckIosAppIdModule: Module { | ||
public func definition() -> ModuleDefinition { | ||
Name("CheckIosAppId") | ||
|
||
Function("isIncorrectAppId") { () -> Bool in | ||
#if targetEnvironment(simulator) | ||
return false | ||
#else | ||
guard let appId = self.extractAppId() else { | ||
return false | ||
} | ||
|
||
return appId.hasSuffix(".*") || (Bundle.main.bundleIdentifier != nil && !appId.contains(Bundle.main.bundleIdentifier!)) | ||
#endif | ||
} | ||
|
||
// Function to get the App ID from the provisioning profile | ||
Function("getAppId") { () -> String? in | ||
#if targetEnvironment(simulator) | ||
return nil | ||
#else | ||
return self.extractAppId() | ||
#endif | ||
} | ||
} | ||
|
||
// Helper function to extract the application-identifier value from the provisioning profile | ||
private func extractAppId() -> String? { | ||
guard let filePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else { | ||
return nil | ||
} | ||
|
||
let fileURL = URL(fileURLWithPath: filePath) | ||
do { | ||
let data = try String(contentsOf: fileURL, encoding: .ascii) | ||
let cleared = data.components(separatedBy: .whitespacesAndNewlines).joined() | ||
|
||
// Search for the application-identifier key and extract its value | ||
if let range = cleared.range(of: "<key>application-identifier</key><string>") { | ||
let substring = cleared[range.upperBound...] | ||
if let endRange = substring.range(of: "</string>") { | ||
let appId = String(substring[..<endRange.lowerBound]) | ||
return appId | ||
} | ||
} | ||
} catch { | ||
print("Error reading provisioning profile: \(error)") | ||
return nil | ||
} | ||
return nil | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/expo/modules/check-ios-app-id/src/CheckIosAppIdModule.android.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { UnavailabilityError } from "expo-modules-core"; | ||
|
||
export default { | ||
isIncorrectAppId(): boolean { | ||
throw new UnavailabilityError("CheckIosAppId", "isIncorrectAppId"); | ||
}, | ||
getAppId(): string { | ||
throw new UnavailabilityError("CheckIosAppId", "getAppId"); | ||
}, | ||
}; |
7 changes: 6 additions & 1 deletion
7
...tificate/src/CheckIosCertificateModule.ts → ...eck-ios-app-id/src/CheckIosAppIdModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { requireNativeModule } from "expo-modules-core"; | ||
|
||
interface CheckIosAppIdModule { | ||
isIncorrectAppId(): boolean; | ||
getAppId(): string; | ||
} | ||
|
||
// It loads the native module object from the JSI or falls back to | ||
// the bridge module (from NativeModulesProxy) if the remote debugger is on. | ||
export default requireNativeModule("CheckIosCertificate"); | ||
export default requireNativeModule("CheckIosAppId") as CheckIosAppIdModule; |
6 changes: 0 additions & 6 deletions
6
apps/expo/modules/check-ios-certificate/expo-module.config.json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
apps/expo/modules/check-ios-certificate/ios/CheckIosCertificateModule.swift
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
apps/expo/modules/check-ios-certificate/src/CheckIosCertificateModule.android.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
import type { MarketplaceSource } from "./src/CheckIosMarketplaceModule"; | ||
import CheckIosMarketplaceModule from "./src/CheckIosMarketplaceModule"; | ||
|
||
export enum MarketplaceSource { | ||
AppStore = "App Store", | ||
TestFlight = "TestFlight", | ||
Marketplace = "Alternative marketplace", | ||
Web = "Website", | ||
Other = "Other", | ||
Unknown = "Unknown", | ||
Error = "Error", | ||
Unavailable = "Unavailable", | ||
} | ||
|
||
interface CheckIosMarketplaceModule { | ||
getCurrentMarketplaceAsync(): Promise<MarketplaceSource>; | ||
} | ||
|
||
export async function getCurrentMarketplaceAsync(): Promise<MarketplaceSource> { | ||
return ( | ||
CheckIosMarketplaceModule as CheckIosMarketplaceModule | ||
).getCurrentMarketplaceAsync(); | ||
return CheckIosMarketplaceModule.getCurrentMarketplaceAsync(); | ||
} |
19 changes: 18 additions & 1 deletion
19
apps/expo/modules/check-ios-marketplace/src/CheckIosMarketplaceModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
import { requireNativeModule } from "expo-modules-core"; | ||
|
||
export enum MarketplaceSource { | ||
AppStore = "App Store", | ||
TestFlight = "TestFlight", | ||
Marketplace = "Alternative marketplace", | ||
Web = "Website", | ||
Other = "Other", | ||
Unknown = "Unknown", | ||
Error = "Error", | ||
Unavailable = "Unavailable", | ||
} | ||
|
||
interface CheckIosMarketplaceModule { | ||
getCurrentMarketplaceAsync(): Promise<MarketplaceSource>; | ||
} | ||
|
||
// It loads the native module object from the JSI or falls back to | ||
// the bridge module (from NativeModulesProxy) if the remote debugger is on. | ||
export default requireNativeModule("CheckIosMarketplace"); | ||
export default requireNativeModule( | ||
"CheckIosMarketplace", | ||
) as CheckIosMarketplaceModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters