से चलाया जा रहा है, मैं प्रोग्रामेटिक रूप से यह निर्धारित करना चाहता हूं कि आईओएस ऐप सीधे एक्सकोड से चलाया जा रहा है (या तो सिम्युलेटर या टिथर्ड डिवाइस पर)। मैंने डीडी डीबीयूजी समाधान को here वर्णित करने का प्रयास किया है, लेकिन जब मैं एक्सकोड से डिस्कनेक्ट करता हूं और ऐप को फिर से चलाता हूं, तो भी यह सोचता है कि यह डीबग मोड में है। मुझे लगता है कि मैं क्या तलाश कर रहा हूँ this functionपता लगाएं कि क्या स्विफ्ट ऐप एक्सकोड
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>
static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.
info.kp_proc.p_flag = 0;
// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
// Call sysctl.
size = sizeof(info);
junk = sysctl(mib, sizeof(mib)/sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);
// We're being debugged if the P_TRACED flag is set.
return ((info.kp_proc.p_flag & P_TRACED) != 0);
}
आप कॉल कर सकते हैं सी कार्यों स्विफ्ट से, तो आपको वास्तव में इसका अनुवाद नहीं करना है। –
मार्टिन, यही वह जवाब है जिसे मैं डालने वाला था, इसे एक उत्तर के रूप में रखें और मैं इसे ऊपर उठाऊंगा। – Knight0fDragon
कोड को स्विफ्ट में बदलने के लिए यहां एक त्वरित, अवांछित प्रयास है (केवल मज़ेदार): https://gist.github.com/getaaron/8d48489274a873835636। मेरे पास अभी इसके साथ खेलने का समय नहीं है, लेकिन शायद यह आपको शुरू कर देगा। –