Inject Dylib changing Offset to jailbreak app

Hi. I want to write a framework or dylib to change memory offset of ios app. I have the issue when I using this code bellow I get the error kernel because app not run under root.

vm_map_t target_task = 0;
kern_return_t kr;
if (task_for_pid(mach_task_self(), pid, &target_task))
{
LOG_ERROR(“Can’t execute task_for_pid! Do you have the right permissions/entitlements?”);
return KERN_FAILURE;
}

How can I fix it? Please help me if you know or have the same problem. Thank in advance.

???

I mean, I want to do it the same way as MSHookMemory does, but it only works on iphone jailbreak. But, I want to write a sample hooking memory work on iphone non jailbreak. Thanks