How do I access 'lost' media assets in iOS mainBundle?

50 views Asked by At

I have had a problem with a video asset not being accessible from mainBundle. I am using XCode 7 and Swift 2.0. I wrote a very simple test app.

var objects = [String]()

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let fm = NSFileManager.defaultManager()
        let path = NSBundle.mainBundle().resourcePath!
        let items = try! fm.contentsOfDirectoryAtPath(path)

        for item in items {
                print ("item = \(item)")
                objects.append(item)
        }

    }

}

I have four media assets in my app: i) testVideo.m4v ii) benbeijing.mov iii) TestVideoCopy.m4v and iv) benbeijing2.mov.

When I run the program I get the following output.

item = Base.lproj
item = benbeijing.mov
item = benbeijing2.mov
item = Frameworks
item = Info.plist
item = mainBundleTests
item = PkgInfo

In other words 2 of the video media items are not listed.

I have played around with titles, suffixes, locations in the mainBundle folder but can't for the life of me figure out why these items can't be found. Any help would be much appreciated.

1

There are 1 answers

2
Sankar Narayanan On

I tried running exactly the same code that you're running. I am able to see that all the files present in my bundle gets printed.

But then, I am assuming you might have missed to add those files to target. This can also be a possible reason.

Can you confirm if you had added all the files that were added to bundle to corresponding target ?

To add the file to target