可以将图片、视频下载到 iPhone 上吗?

发布于 2024-08-19 07:10:52 字数 110 浏览 5 评论 0原文

我正在构建一个应用程序,在其中更新图像和视频,并且想知道是否可以从网络服务下载视频/图像,该网络服务将以编程方式在 iPhone 上的某个位置托管这些资产?

也许通过curl 服务或ftp?

I am building an application where we do updates for images and videos and was wondering if it was possible to download videos/images from a web-service that will host these assets somewhere on the iphone programatically?

Maybe through a curl service or ftp?

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

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

发布评论

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

评论(3

尴尬癌患者 2024-08-26 07:10:52

您可以将任何您喜欢的内容下载到手机上(当然,受带宽和存储限制)。然而,实际上只有某些格式的电影(例如 m4v,而不是 wmv 文件)才能在设备上播放。

You can download anything you like onto the phone (subject, of course, to bandwidth and storage constraints). Only movies of certain formats (m4v, not wmv files, for example) will actually be PLAYABLE on the device, however.

疯到世界奔溃 2024-08-26 07:10:52

将文件从远程服务器下载到 iPhone 的方法有很多种,有些甚至只需要一行代码。

最简单的方法可能是:

[NSData dataWithContentsOfURL:fileURL]

但这会阻止您的代码,直到下载文件,更可用的解决方案可能是使用 NSURLConnection

NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[NSURLConnection connectionWithRequest:request delegate:self];

并实现 NSURLConnection 的委托方法

保存文件也可以通过多种方式完成,最简单的可能是:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"newFileName.ext"];
[NSData writeToFile:localFilePath atomically:YES];

这会将数据保存到应用程序的文档目录中

There are many ways to download files from remote servers to the iPhone, some even require just one line of code.

The most simple way might be:

[NSData dataWithContentsOfURL:fileURL]

But this will block your code till the file is downloaded, a more usable solution is probably to use NSURLConnection

NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[NSURLConnection connectionWithRequest:request delegate:self];

And implement the delegate methods for NSURLConnection

Saving files can be done in numerous ways as well, simplest might be:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"newFileName.ext"];
[NSData writeToFile:localFilePath atomically:YES];

Which will save the data to the documents directory of your app

天冷不及心凉 2024-08-26 07:10:52

是的,这是可能的,您可以将文件写入多个位置(tmp 和 Documents) - 如果您将下载的文件写入 Documents 目录,则该文件将在您下次启动应用程序时可用,甚至会在之间持续存在您的应用程序升级时的版本。您还可以写入和编辑 Documents 目录中的文件,这与应用程序的 Resource 目录中的文件在安装后无法更新不同。这对您来说很棘手,因为对于任何给定的文件,都会有应用程序安装(在资源中)附带的版本,您无法覆盖或编辑该版本,然后在文档中出现新版本,因此您的逻辑需要查看如果文档中有较新版本的内容,请播放该内容,然后回退到应用程序的资源目录。

对于下载,我建议使用可爱的 ASIHTTPRequest 库来将文件异步/后台下载到磁盘,并提供进度信息和带宽限制(这是关键)。

http://allseeing-i.com/ASIHTTPRequest/

要考虑的另一部分是当不在 WiFi 上时,Apple 会拒绝过多使用带宽的应用程序,因此您需要将大下载限制为仅通过 WiFi,或者需要将带宽限制在 1mb/分钟左右。 ASIHTTPRequest 在这方面做得很好,虽然不能保证不会被 Apple 限制,但它比不限制要好得多。

还值得一提的是,对于流媒体视频,你现在必须使用http直播,但如果你下载时不播放,只是下载稍后播放,我想你需要担心的就是不会结束带宽限制,使用有效的格式,并将文件写入文档,以便在启动和应用程序更新之间保留该文件。

yes this is possible, there are multiple places (tmp and Documents) that you can write files to - if you write the downloaded file to the Documents directory, the file will be available the next time you launch the app, and will even persist between versions of your app as it is upgraded. You can also write to and edit files in the Documents directory, unlike files in your app's Resource directory that cannot update after install. This will be tricky for you, as for any given file there will be the version that came with the app install (in the Resources) that you cannot overwrite or edit, and then a new version in Documents, so your logic ill need to see if there is a newer version of the content in Documents, and play that, and than fallback on the app's Resource directory.

For downloading, I recommend using the lovely all seeing I ASIHTTPRequest lib for doing nice async/background download of files to disk, with progress information and bandwidth throttling (this is key).

http://allseeing-i.com/ASIHTTPRequest/

The other part of this to consider is that Apple will reject apps for excessive bandwidth use when not on WiFi, so either you need to limit big downloads to only over WiFi, or you need to throttle bandwidth to about 1mb/minute. ASIHTTPRequest does this very well, and while it is no guarantee against being dinged by Apple, it is much better than not throttling.

It is also worth mentioning that for streamed video, you now have to use http live streaming, but if you are not playing as it downloads, and are only downloading it for playback later, I think all you need to worry about is not going over the bandwidth limits, using a format that works, and writing the file to Documents so it will be retained between launches and app updates.

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