Skip to content

Instantly share code, notes, and snippets.

@Wooder
Created November 21, 2017 15:32
Show Gist options
  • Save Wooder/b9434ffef93cb9b3bc1912d94c86afe6 to your computer and use it in GitHub Desktop.
Save Wooder/b9434ffef93cb9b3bc1912d94c86afe6 to your computer and use it in GitHub Desktop.
Swift Code that check if the debugger is attached to your iOS Device (App runs in XCode) while running your app
#if DEV
fileprivate func isDebuggerAttached() -> Bool {
var info = kinfo_proc()
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
return (info.kp_proc.p_flag & P_TRACED) != 0
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment