访问和下载点播资源iOS9 [英] accessing and downloading on demand resources iOS9

查看:140
本文介绍了访问和下载点播资源iOS9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现新的iOS9功能应用程序精简,我了解如何在Xcode 7中标记图像并启用按需资源,但是我不了解如何在我的应用程序中实现NSBundleResourceRequest,有人可以帮助我,那会很大感激

I am trying to implement new iOS9 feature app thinning, I understood how tag an image and enable on demand resource in Xcode 7 but I don't understand how to implement NSBundleResourceRequest in my app, can someone help me, that would greatly appreciated

推荐答案

首先,检查资源是否可用.否则下载它们.

First, check if the resources are available. Else download them.

这是我使用的swift代码

let tags = NSSet(array: ["tag1","tag2"])
let resourceRequest = NSBundleResourceRequest(tags: tags as! Set<String>)
resourceRequest.conditionallyBeginAccessingResourcesWithCompletionHandler {(resourcesAvailable: Bool) -> Void in
    if resourcesAvailable {
        // Do something with the resources
    } else {
        resourceRequest.beginAccessingResourcesWithCompletionHandler {(err: NSError?) -> Void in
            if let error = err {
                print("Error: \(error)")
            } else {
                // Do something with the resources
            }
        }
    }
}

我还发现 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆