English 中文(简体)
从程序上获得其他应用的目录途径?
原标题:Programmatically get the directory path of other application from process pid on iOS system?
  • 时间:2012-04-15 06:21:57
  •  标签:
  • ios
  • process

我如何能够从程序上获得其他应用的指南?

Seems that there is no proc_pidpath calls onOS.

最佳回答

“SiOS”和“sysctl

- (NSString *)pathFromProcessID:(NSUInteger)pid {

    // First ask the system how big a buffer we should allocate
    int mib[3] = {CTL_KERN, KERN_ARGMAX, 0};

    size_t argmaxsize = sizeof(size_t);
    size_t size;

    int ret = sysctl(mib, 2, &size, &argmaxsize, NULL, 0);

    if (ret != 0) {
        NSLog(@"Error  %s  (%d) getting KERN_ARGMAX", strerror(errno), errno);            

        return nil;
    }

    // Then we can get the path information we actually want
    mib[1] = KERN_PROCARGS2;
    mib[2] = (int)pid;

    char *procargv = malloc(size);

    ret = sysctl(mib, 3, procargv, &size, NULL, 0);

    if (ret != 0) {
        NSLog(@"Error  %s  (%d) for pid %d", strerror(errno), errno, pid);            

        free(procargv);

        return nil;
    }

    // procargv is actually a data structure.  
    // The path is at procargv + sizeof(int)        
    NSString *path = [NSString stringWithCString:(procargv + sizeof(int))
                                        encoding:NSASCIIStringEncoding];

    free(procargv);

    return(path);
}
问题回答

相对于此,Siper的物品受到的限制更大。 如果您愿意在申请之间分享档案,考虑使用i±,那么,鉴于开发商属于同一用途,它将允许你查阅不同平台甚至不同平台的档案。 Ray Wenderlich写道:





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...