Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndreyAnt/f6740131c3f89df414d536ec38fdea85 to your computer and use it in GitHub Desktop.
Save AndreyAnt/f6740131c3f89df414d536ec38fdea85 to your computer and use it in GitHub Desktop.
autofill SMS code webview crash https://openradar.appspot.com/7428013
func swizzleReplacingCharacters() {
let originalMethod = class_getInstanceMethod(
NSString.self, #selector(NSString.replacingCharacters(in:with:)))
let swizzledMethod = class_getInstanceMethod(
NSString.self, #selector(NSString.swizzledReplacingCharacters(in:with:)))
guard let original = originalMethod, let swizzled = swizzledMethod else {
return
}
method_exchangeImplementations(original, swizzled)
}
extension NSString {
@objc
func swizzledReplacingCharacters(in range: NSRange, with replacement: String) -> String {
/// By simply calling the original method the nil argument is handled. :shrug: :ok:
///
/// (yes, we will call the original method and not ourselves even though it looks like it,
/// because the methods have been swapped.)
return self.swizzledReplacingCharacters(in: range, with: replacement)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment