From 3b1b46b4f11fec25b966902ecc54f42691f1ab85 Mon Sep 17 00:00:00 2001 From: Jayden Date: Thu, 9 May 2024 12:35:47 +0800 Subject: [PATCH] Update Swizzle.swift --- .../Extensions/ObjCRuntime/Swizzle.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift b/Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift index 401326a..229be06 100644 --- a/Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift +++ b/Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift @@ -32,6 +32,20 @@ public class Swizzle { guard let originalMethod = class_getClassMethod(cls, originalSelector) else { return } guard let customMethod = class_getClassMethod(cls, customSelector) else { return } - method_exchangeImplementations(originalMethod, customMethod) + if class_addMethod( + cls, + originalSelector, + method_getImplementation(customMethod), + method_getTypeEncoding(customMethod) + ) { + class_replaceMethod( + cls, + customSelector, + method_getImplementation(originalMethod), + method_getTypeEncoding(originalMethod) + ) + } else { + method_exchangeImplementations(originalMethod, customMethod) + } } }