iOS 应用程序启动后渐进式资源(或资源包)加载
我希望在我的 iOS 应用程序中添加更多渐进式资源加载,有点像 ZeptoLab 为 Cut the Rope 所做的那样。我想减少用户在应用程序加载时花在静态 Default.png 上的时间,并希望更快地到达某个启动屏幕,在那里我可以显示进度条(我花了一些时间在 Flash 中进行开发,其中“预加载器”) ' 是常态)。
我推测我可能必须为此使用资源包。我希望仍然保留 Xcode 中的所有文件,而不是从其他位置加载。
所以我已经看到了如何加载资源包的示例 -
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"MyBundle" ofType:@"bundle"];
NSString *imageName = [myBundle pathForResource:@"someImage" ofType:@"png"];
但我想找到有关如何以下操作的示例:
- 异步运行它,我想通过使用另一个线程
- 跟踪该包已加载的量
- 知道该包包含多少,所以我可以计算已加载的捆绑包的百分比。
我还想知道 - 使用资源包是否会改变我的 iOS 应用程序加载文件的方式/时间?
或者选择不将文件添加到 Xcode 项目设置中的复制/构建阶段是正确的方法吗?
谢谢大家!
I'm looking to add more gradual/progressive asset loading to my iOS app, a bit like ZeptoLab do for Cut the Rope. I want to reduce the time the user spends on the static Default.png while the app loads, and hopefully arrive quicker to some Splash screen, where I can show a progress bar (I've spent some time developing in Flash, where 'preloaders' are the norm).
I gathered that I may have to use asset bundles for this. I want to still have all the files in Xcode, rather than being loaded from another location.
So I've seen examples on how to load an asset bundle -
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"MyBundle" ofType:@"bundle"];
NSString *imageName = [myBundle pathForResource:@"someImage" ofType:@"png"];
But I wanted to find examples on how to:
- run this asynchronously, I guess by using another thread
- track how much of this bundle has loaded
- know how much this bundle contains, so I can calculate the percentage of the bundle that's been loaded.
I also wanted to know - does using asset bundles change how/when my files will be loaded by my iOS application?
Or is the correct approach to choose not to add files to the copy/build phases in my Xcode project's settings?
Thanks everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
值得庆幸的是,文件系统访问是线程安全的,因此在线程上加载文件正是您所需要的。我听说过 ios 的一些中央调度的东西......但是 pthreads 也工作得很好。我没有可以分享的示例代码,但我可以说,如果您已经在某种程度上了解线程原语(例如锁,甚至具有原子操作的无锁技术等),那么这并不是太难,
您不必使用单独的包为了实现这一点 - 尽管使用它们也没有坏处(例如,将您想要动态加载的资产分开)
thankfully file system access is threadsafe so loading a file on a thread is exactly what you need. i've heard of some grand central dispatch thing for ios... however pthreads work just fine as well. i do not have example code i can share, but i can say that this is not too hard if you already understand threading primitives to some degree (e.g. locks or even lockless techniques with atomic operations etc.)
you do not have to use separate bundles to achieve this - although there is no harm in using them either (for instance to keep separate those assets you want to load dynamically)