GBA-8-19/CGame/Extensions/Bundle+SwizzleBundleID.swift
bluesea 66c5202be8 s
2024-06-14 18:12:40 +08:00

57 lines
1.6 KiB
Swift

//
// Bundle+SwizzleBundleID.swift
// Hthik
//
// Created by Hthik on 8/7/19.
// Copyright © 2019 Hthik. All rights reserved.
//
import Foundation
import ObjectiveC.runtime
extension Bundle
{
@objc private var swizzled_infoDictionary: [String : Any]? {
var infoDictionary = self.swizzled_infoDictionary
#if LITE
#if BETA
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.Lite.Beta"
#else
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.Lite"
#endif
#else
#if BETA
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.AltStore.Beta"
#else
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.AltStore"
#endif
#endif
return infoDictionary
}
public static func swizzleBundleID(handler: () -> Void)
{
let bundleClass: AnyClass = Bundle.self
guard
let originalMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.infoDictionary)),
let swizzledMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.swizzled_infoDictionary))
else {
print("Failed to swizzle Bundle.infoDictionary.")
return
}
method_exchangeImplementations(originalMethod, swizzledMethod)
handler()
method_exchangeImplementations(swizzledMethod, originalMethod)
}
}