从网络加载内容的最佳方式

发布于 2024-09-28 12:42:29 字数 842 浏览 1 评论 0原文

我有一个应用程序,它显示 10 个图像,每个图像都与一个按钮和一个 URL 链接关联。我想发布此应用程序,但能够通过网络更新图像和链接,而无需对应用程序进行更新。

我知道我可以像这样从网络中提取图像:

NSURL *url = [NSURL URLWithString: @"http://example.com/image.png"];
 NSData *data = [NSData dataWithContentsOfURL: url];
 UIImage *image = [UIImage imageWithData: data];
 UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

我认为也可以从网络中提取 plist?

.xib 和 .h/.m 文件怎么样?我可以让我的应用程序在每次运行时检查某个 URL 是否有新的 .xib/.h/.m 文件,当我在两周内将这些文件上传到该 URL 时,运行该应用程序的人将让它加载新的文件?

因此,我不会像这样从我的资源中加载类/xib:

UIViewController *nextController = [[ClassName alloc] initWithNibName:@"ClassName" bundle:nil];

我会以某种方式用从网络上提取的新数据替换 ClassName 吗?

我见过一些应用程序可以从网络获取新数据(假设通常是简单的图像/文本 - 例如 Doodle Jump 中偶尔出现的“新闻”更新),而不需要用户下载应用程序的更新。任何有关实现这一目标的第一步的帮助将不胜感激......谢谢!

I have an app which displays 10 images and each image is associated with a button and a URL link. I would like to release this app, but be able to update the images and links via the web without needing to do an update to the app.

I know that I can pull images from the web like so:

NSURL *url = [NSURL URLWithString: @"http://example.com/image.png"];
 NSData *data = [NSData dataWithContentsOfURL: url];
 UIImage *image = [UIImage imageWithData: data];
 UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

I assume that it is also possible to pull a plist from the web as well?

What about a .xib and .h/.m files? Could I have my app check a certain URL for new .xib/.h/.m files each time it runs, and when I upload these files to that URL in two weeks time, people who run the app will have it load the new files?

So instead of loading a class/xib from my resources like this:

UIViewController *nextController = [[ClassName alloc] initWithNibName:@"ClassName" bundle:nil];

I would somehow replace the ClassName with new data pulled from the web?

I have seen apps that pull in new data (granted it's usually simple images/text - such as the occasional "news" updates in Doodle Jump) from the web without requiring users to download an update for the app. Any help with the first steps towards making this happen would be greatly appreciated... Thanks!

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

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

发布评论

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

评论(2

赢得她心 2024-10-05 12:42:29

将应用程序中捆绑的所有起始材料存储在资源文件夹内。首次加载时,以编程方式将所有该材料复制到捆绑包库路径。然后,您的应用程序应该只处理库目录内的数据。当您的应用程序首次连接到网络时,您可以将任何新数据保存到用户的库路径并覆盖旧数据。

编译后无法写入应用程序包目录,因为这会破坏 Apple 的签名。

显然,这只是一个高层建议。如果不确切知道你想做什么,很难给出详细的答案。但是,是的,下载和存储数据是允许的,只是不能在应用程序包内下载和存储数据。不幸的是,您无法向其发送新的 .h/.m 文件或 xib。

Store all of your starting material that's bundled in your app inside the resource folder. On first load, programatically copy all of that material to the bundle Library path. Your app should then only deal with the data inside the library directory. When your app first connects to the web, you can save any new data to the user's library path and overwrite the old stuff.

It's impossible to write to the app bundle directory after it's been compiled, because that breaks Apple's signature.

This is just a high level suggestion, obviously. Without knowing exactly what you want to do it's hard to give a detailed answer. But yes, downloading and storing data is permitted, just not inside the app bundle. You cannot send it new .h/.m files or xibs, unfortunately.

灵芸 2024-10-05 12:42:29

您可以从网络加载资源,但无法在正在运行的应用程序中“编译”任何内容,因此 .m/.mh/.xib 不可用。

您当然可以加载 plist(或其他数据文件)并使用它来引用不同的图像和链接。 (从这个意义上说,上面的 http://example.com/image.png 可能是动态的。)

You can load resources from the web, but you cannot "compile" anything in a running app, so the .m/.mh/.xib aren't useable.

You can certainly load a plist (or other data file) and use that to reference different images and links. (The http://example.com/image.png above could be dynamic in this sense.)

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