Skip to content

Commit

Permalink
Patch for Loop 3.4.4 to restore TestFlight expiration date (#2242)
Browse files Browse the repository at this point in the history
* Adjust provisioning profile path in script for Xcode 16 compatibility

* Bump version to 3.4.4

---------

Co-authored-by: Jonas Björkert <jonas@bjorkert.se>
  • Loading branch information
marionbarker and bjorkert authored Oct 9, 2024
1 parent a91352a commit 20c313c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 43 deletions.
46 changes: 5 additions & 41 deletions Common/Models/BuildDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ class BuildDetails {
static var `default` = BuildDetails()

let dict: [String: Any]
private var cachedProfileExpirationDate: Date?

init() {
guard let url = Bundle.main.url(forResource: "BuildDetails", withExtension: ".plist"),
let data = try? Data(contentsOf: url),
let parsed = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else
let data = try? Data(contentsOf: url),
let parsed = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else
{
dict = [:]
return
}
dict = parsed
cachedProfileExpirationDate = loadProfileExpirationDate()
}

var buildDateString: String? {
Expand All @@ -48,11 +46,11 @@ class BuildDetails {
}

var profileExpiration: Date? {
return cachedProfileExpirationDate
return dict["com-loopkit-Loop-profile-expiration"] as? Date
}

var profileExpirationString: String {
if let profileExpiration = cachedProfileExpirationDate {
if let profileExpiration = profileExpiration {
return "\(profileExpiration)"
} else {
return "N/A"
Expand All @@ -65,41 +63,7 @@ class BuildDetails {
}

var workspaceGitBranch: String? {
return dict["com-loopkit-LoopWorkspace-git-branch"] as? String
}

private func loadProfileExpirationDate() -> Date? {
guard
let profilePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision"),
let profileData = try? Data(contentsOf: URL(fileURLWithPath: profilePath)),
let profileNSString = NSString(data: profileData, encoding: String.Encoding.ascii.rawValue)
else {
print(
"WARNING: Could not find or read `embedded.mobileprovision`. If running on Simulator, there are no provisioning profiles."
)
return nil
}

let regexPattern = "<key>ExpirationDate</key>[\\W]*?<date>(.*?)</date>"
guard let regex = try? NSRegularExpression(pattern: regexPattern, options: []),
let match = regex.firstMatch(
in: profileNSString as String,
options: [],
range: NSRange(location: 0, length: profileNSString.length)
),
let range = Range(match.range(at: 1), in: profileNSString as String)
else {
print("Warning: Could not create regex or find match.")
return nil
}

let dateString = String(profileNSString.substring(with: NSRange(range, in: profileNSString as String)))
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

return dateFormatter.date(from: dateString)
return dict["com-loopkit-LoopWorkspace-git-branch"] as? String
}
}

26 changes: 25 additions & 1 deletion Scripts/capture-build-details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ info() {

info_plist_path="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/BuildDetails.plist"
xcode_build_version=${XCODE_PRODUCT_BUILD_VERSION:-$(xcodebuild -version | grep version | cut -d ' ' -f 3)}

while [[ $# -gt 0 ]]
do
case $1 in
-i|--info-plist-path)
info_plist_path="${2}"
shift 2
;;
-p|--provisioning-profile-path)
provisioning_profile_path="${2}"
shift 2
;;
esac
done

Expand All @@ -42,7 +47,6 @@ fi

if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
error "File does not exist: ${info_plist_path}"
#error "Must provide valid --info-plist-path, or have valid \${BUILT_PRODUCTS_DIR} and \${INFOPLIST_PATH} set."
fi

info "Gathering build details in ${PWD}"
Expand All @@ -62,6 +66,26 @@ plutil -replace com-loopkit-Loop-srcroot -string "${PWD}" "${info_plist_path}"
plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${info_plist_path}"
plutil -replace com-loopkit-Loop-xcode-version -string "${xcode_build_version}" "${info_plist_path}"

# Determine the provisioning profile path
if [ -z "${provisioning_profile_path}" ]; then
if [ -e "${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" ]; then
provisioning_profile_path="${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision"
elif [ -e "${HOME}/Library/Developer/Xcode/UserData/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" ]; then
provisioning_profile_path="${HOME}/Library/Developer/Xcode/UserData/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision"
else
warn "Provisioning profile not found in expected locations"
fi
fi

if [ -e "${provisioning_profile_path}" ]; then
profile_expire_date=$(security cms -D -i "${provisioning_profile_path}" | plutil -p - | grep ExpirationDate | cut -b 23-)
# Convert to plutil format
profile_expire_date=$(date -j -f "%Y-%m-%d %H:%M:%S" "${profile_expire_date}" +"%Y-%m-%dT%H:%M:%SZ")
plutil -replace com-loopkit-Loop-profile-expiration -date "${profile_expire_date}" "${info_plist_path}"
else
warn "Invalid provisioning profile path ${provisioning_profile_path}"
fi

# determine if this is a workspace build
# if so, fill out the git revision and branch
if [ -e ../.git ]
Expand Down
2 changes: 1 addition & 1 deletion Version.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

// Version [DEFAULT]
LOOP_MARKETING_VERSION = 3.4.3
LOOP_MARKETING_VERSION = 3.4.4
CURRENT_PROJECT_VERSION = 57

// Optional override
Expand Down

0 comments on commit 20c313c

Please sign in to comment.