一个测试的项目,给自己的应用签task_for_pid-allow。
在工程中创建了pidTest.entitlements,如下图:
ViewController.m中代码非常简单,如下:
#import <Foundation/NSProcessInfo.h>
#import <mach-o/dyld_images.h>
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
kern_return_t rc;
mach_port_t task;
int pid;
pid = [[NSProcessInfo processInfo] processIdentifier];//获取进程的id,即平常使用ps -e | grep xxx得到的进程端口号
rc = task_for_pid(mach_task_self(), pid, &task);
if (rc) {
fprintf (stderr, "task_for_pid() failed with error %d - %s\n", rc, mach_error_string(rc));
exit(1);
}
printf ("RC %d - Task: %d\n",rc, task);
}
但是Xcode无法编译通过,提示如下:
Showing All Messages
Automatic signing is unable to resolve an issue with the “get_pid” target’s entitlements. Automatic signing can’t add the task_for_pid-allow entitlements to your provisioning profile. Switch to manual signing and resolve the issue by downloading a matching provisioning profile from the developer website. Alternatively, to continue using automatic signing, remove these entitlements from your entitlements file and their associated functionality from your code. (in target ‘get_pid’)
其中重点是Automatic signing can’t add the task_for_pid-allow entitlements to your provisioning profile,以及Switch to manual signing。