将 iPhone 照片库路径保存到 Plist

发布于 2024-10-16 09:59:33 字数 278 浏览 3 评论 0原文

我想将 iPhone 主照片库中特定照片的图像路径字符串保存在 plist 文件中。

这样稍后我就可以在 Web 视图中调用 plist 图像路径字符串并查看照片。

我知道我需要绝对路径,它可能与文档目录的路径类似,但是:

1.) 如何获取特定照片的照片名称?

2.)我是否需要将绝对路径字符串附加到照片名称,然后写入plist?

3.)我的应用程序的每次安装都会改变路径 - 这将使硬编码的绝对路径无法使用?

有专业人士想解决这个难题吗?

I want to save an image path string for a particular photo from the main iphone photo library in a plist file.

So that later I can call the plist image path string in a web view and see the photo.

I know I need the absolute path which is probably a similar path to the documents directory but:

1.) How do I get the photo name of the particular photo?

2.) Do I need to append the absolute path string to the photo name and then write to the plist?

3.) Will the path change for every install of my app - which would make a hard coded absolute path impossible to use?

Any pros want to tackle this conundrum?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋千易 2024-10-23 09:59:33

如果您正在构建低于 iOS4.0 的应用程序,那么您可以使用 UIImagePickerController 类。这将允许用户从手机相册中选择一张图像,然后您可以将其保存在应用程序的文档目录中,并将相应的链接保存在 info.plist 文件中。当您的应用程序被卸载时,文档目录会被删除,因此您也会丢失路径。

更好的方法是使用 ALAssetsLibrary。 iPhone 中的每张照片都由您可以保存的唯一 URL 表示,并且您可以使用该 URL 引用特定图像。有一个很好的教程博客这可以帮助您开始使用它。

现在,在您的问题中,您正在谈论一张特定照片。您不能只知道库中的任何特定照片,除非您让用户选择一张。这让我回答你的最后一个问题。该特定图像的 URL 是恒定的(直到 iPhone 重置),但除非您有任何方法在应用程序的每次安装之间保留该信息(这里到底意味着什么?),我不知道不知道唯一的 URL 对您有什么帮助。

编辑:
刚刚看到sdk 4.0的标签,请忽略第一种情况(<4.0部分)。

If you are building an app targeting lower than iOS4.0, then you may use UIImagePickerController Class. This will let user pick one image from the phone album, which then, you can save in your app's documents directory and save the corresponding link in the info.plist file. The documents directory gets deleted when your app gets uninstalled, and so you lose the path as well.

A better way, with a disadvantage of restricting this feature (and so your app if its a main feature) to only iOS4.0 and above, would be using ALAssetsLibrary. Each photo in the iphone is represented by a unique URL that you can save, and you can refer to a particular image using that url. There is a nice tutorial blog that can help you get started with it.

Now, in your question, you are talking about a particular photo. You can not just know of any particular photo in the library, unless you let the user pick one. This brings me to answer your last question. The URL is constant for that particular image (till the iphone is reset), but unless you have any way of keeping that information between every install of your app (what exactly do mean here?), I don't know how being a unique URL is going to help you here.

EDIT:
Just saw the tag of sdk 4.0 there, please ignore the first case (the <4.0 part).

别想她 2024-10-23 09:59:33

好吧,我想我想使用 UIImagePickerController!

这是我的代码:

- (void)viewDidLoad {

    self.iconPicker = [[UIImagePickerController alloc] init];
    self.iconPicker.allowsEditing = YES;
    self.iconPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    self.iconPicker.delegate = self;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    iconImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

    [picker dismissModalViewControllerAnimated:YES];
    [picker release];
}

- (IBAction)save {

    [plist.data setValue:iconImage.image forKey:@"Icon"];
    [plist.data writeToFile:plist.file atomically:YES];

    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

How do I save the image name of theedited image in plist string.

我知道我不想保存 CGImage 数据或其他任何内容,因为加载大小。

我想我可以通过将所有 HTML 放入字符串对象中,然后将变量添加到我需要包含的对象中,将 xcode 变量传递到 HTML 中...

所以我可以创建照片目录的路径,但我需要知道如何获取从 UIImagePickerController 保存的已编辑图像的名称???

OK I think I want to use the UIImagePickerController!

Here is my code:

- (void)viewDidLoad {

    self.iconPicker = [[UIImagePickerController alloc] init];
    self.iconPicker.allowsEditing = YES;
    self.iconPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    self.iconPicker.delegate = self;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    iconImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

    [picker dismissModalViewControllerAnimated:YES];
    [picker release];
}

- (IBAction)save {

    [plist.data setValue:iconImage.image forKey:@"Icon"];
    [plist.data writeToFile:plist.file atomically:YES];

    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

How do I save the image name of the edited image in plist string.

I know I don't want to save the CGImage data or whatever because of the load size.

I think I can pass an xcode variable into HTML through putting all my HTML into string objects and then adding variables to the objects where I need includes...

So I can create a path to the photo directory but I need to know how to get the name of the saved edited image from UIImagePickerController???

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文