开发者

app can't write file on iPhone if the app is transfered to iPhone by ssh

I am using a jailbroken iPhone and i transfered an app to its /Applications. I chmod the app to 0777.

The app can execute but this part of code acts differently on simulator and device. on simulator,the length is the real length of the upload.jpeg, But on device, the length become 0;

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *uploadFilePath = [documentsDirectory stringByAppendingPathComponent:@"upload.jpeg"];

    [UIImageJPEGRepresentation(imageForUpLoad,1) writeToFile:uploadFilePath ato开发者_运维问答mically:YES];
    NSData* dataToUpload = [[NSData alloc] initWithContentsOfFile:uploadFilePath];
    int length = [dataToUpload length];
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"jpeg length"
                                                    message:[NSString stringWithFormat:@"%d",length]
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil, nil];
    [alert show];
    [alert release];


it's a little tricky but I found where the problem lies. change this:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *uploadFilePath = [documentsDirectory stringByAppendingPathComponent:@"upload.jpeg"];

to this:

NSString* uploadFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"upload.jpeg"];

add it will be fine. But I can't figure out why I can't use document directory on iOS 4.3 device. When I use iOS 4.2 device, the former code is also OK.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜