iOS app and itunes file transfer method and description of the iOS app file structure

Source: Internet
Author: User

Ext.: http://www.xiaoyaoli.com/?p=368

Just like many iOS player apps, this article writes a program that allows you to put files through itunes, such as writing a music player program, placing a song file through Itune, and then playing the song through this app. First, I created an ordinary Singleview program called Filesharedemo. Here's how to transfer files from itunes to the app:

Can see like Gplayer,aceplayer player, video resources in this way transmission is very common (many Apple users really do not know this can transfer data), here I created an app called Filesharedemo, can see, can also drag data inside, Drag a song here 2.mp3, but by default the app created is not available in the left column, you need to press the plist inside add a line:

The next task is to determine if there is any import, the following code I wrote in the Viewdidload:

Nsfilemanager *manager=[nsfilemanager Defaultmanager];

NSString *path=[[nshomedirectory () stringbyappendingpathcomponent:@ "Documents"] stringbyappendingpathcomponent:@ " 2.mp3″];

if ([manager Fileexistsatpath:path]) {

[Email protected] "have file";

}else {

[Email protected] "has no file";

}

NSLog (@ "Nshomedirectory%@", Nshomedirectory ());

Here are a few things to explain, first nshomedirectory () print out is

/var/mobile/applications/8f01293c-c02d-4ef8-a9f7-1a7b10944f33

This is the path of the program, 8F01293C-C02D-4EF8-A9F7-1A7B10944F33 is a unique tag for each app, such as Angry Birds will be another string of information, specifically why not clear. Then I added/documents and/2.mp3, and through [manager Fileexistsatpath:path] to determine that the path does not exist, print it with a label. If you drag it in, you can see that the label's contents are "file", and you can see the/VAR/MOBILE/APPLICATIONS/8F01293C-C02D-4EF8-A9F7-1A7B10944F33 by using the label information that the program runs. /documents/2.mp3 is the path to the imported file.

We can then use this code to play the song:

nserror* err;

Player = [[Avaudioplayer alloc]

Initwithcontentsofurl:[nsurl Fileurlwithpath:path]

Error:&err];

player.volume=0.7;

[Player play];

The previous path can be used directly here.

The structure of the file is again added below:

Each program will contain these files, documents is the itunes import of the document storage place, Filesharedemo is the Xcode project package, if the project through Xcode to put material what is here, the latter two do not know what the specific role.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.