如何从 Xcode 的“支持文件”访问文件群组,在应用程序中?

发布于 2024-12-09 01:49:07 字数 419 浏览 0 评论 0原文

我有一个应用程序,现在我几乎已经完成了,在数据输入流程结束时发送电子邮件,发送两个 .pdf 文件。其中一个是根据输入的数据生成的,另一个是静态文件,在每个实例中都相同。

第一个 pdf 生成正常,它已保存到应用程序的“文档”文件夹中,并且我已成功附加到电子邮件以进行发送。这是第二个 .pdf,我在应用程序外部制作并试图添加的一个,这让我感到悲伤。

我已将其添加到 Xcode 项目中的“支持文件”文件夹中,但在此处和其他在线位置进行了大量搜索后,我无法弄清楚如何访问该文件以便能够将其作为附件添加到电子邮件。 从 Xcode 中的 Organizer“下载”应用程序的数据后,我可以看到该文件不存在于任何地方;大概是因为 Xcode 可以看到该文件没有在任何地方使用,所以它没有在构建时添加它(这很大程度上是我的假设),但我不知道如何在任何地方引用它,因为我不知道在哪里那就来参考一下吧!

I have an app that I've almost finish now that emails, at the end of a data entry flow, two .pdf files. One of these is generated from the entered data, the other is a static file that will be the same in every instance.

The first pdf is generating fine, it's saved to the apps 'documents' folder, and I have successfully attached to to an email for sending. It's the second .pdf, one that I made externally to the app and am trying to add, that is causing me grief.

I've added it to the 'Supporting Files' folder within my Xcode project, but after much searching on here, and elsewhere online, I can't work out how to access that file to be able to add it as an attachment in the email.
Having "downloaded" the app's data from the Organizer in Xcode, I can see that the file isn't there anywhere; presumably because Xcode can see that the file isn't being used anywhere, it's not adding it at build time (very much an assumption on my part), but I don't know how to reference it anywhere because I don't know where it will be to reference it!

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

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

发布评论

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

评论(3

盗琴音 2024-12-16 01:49:07

Xcode 不会在您的应用程序包中生成与组对应的任何文件夹。只需确保您的 pdf 存在于目标构建阶段的复制捆绑资源中即可。然后,您可以访问 [[NSBundle mainBundle] bundlePath] 路径下的资源。

The Xcode does not generate any folders in your app bundle that corresponds to groups. Just make sure that your pdf is present in Copy Bundle Resources in your target's Build Phases. You then access your resource under [[NSBundle mainBundle] bundlePath] path.

我要还你自由 2024-12-16 01:49:07

如果您想访问图像,此代码是一个很好的示例,说明如何:

NSString* imageName = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];

If you want to access an image, this code is a good sample as how to:

NSString* imageName = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];
冬天旳寂寞 2024-12-16 01:49:07

在 Swift 中,您可以使用以下函数获取包资源路径:

func currentresourcepath () -> String
{
    return (NSBundle.mainBundle().bundlePath + "/Contents/Resources/")
}

In Swift you can get the bundle-resorce-path with the following function:

func currentresourcepath () -> String
{
    return (NSBundle.mainBundle().bundlePath + "/Contents/Resources/")
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文