开发者

how to implement import/exporting files to the app?

my goals (this is for training purpose):

  1. User can create(50%DONE)/edit/delete/view a created Quiz!
  2. The Quiz has a name, desc, type, ... (DONE) and an array with objects like this:@"Question:Answer"
  3. user should be able to export/import one/more qu开发者_运维知识库iz(s) via email attachments! however so far I have came:

the quiz class: .h

   @interface quiz : NSObject {
        NSString *title, *description, *type ....;
        NSArray *words;

    }

    @property(nonatomic,retain)NSString *title, *description, *type ... ;
    @property(nonatomic,retain)NSArray *words;
    @end

I give all the info it needs:

quiz *newquiz = [[quiz alloc] init];
        newquiz.title = exName.text;
        newquiz.description = myDesc;
        newquiz.type = myType;
            newquiz.array = wordsArray;
        ....

ok now I have an NSObject. Now I dont know what to do? Can somebody explain me in some easy and clean steps that I should do to achieve my goals?

my thoughts about what to do next:

  1. I need to store the NSobject locally. maybe writeToFile:@"filename.obj". I have no idea how to implement this!


Not really sure what your question is an there are like 10 questions in your snippet there. But the only thing that might be hard is the importing/exporting stuff, so ill help with that.

Depends on the system you're using. In the jailbroken community, you can access the files outside of your sandbox... in the oppressed world of stock iphones, you can't.

METHOD 1: Now, lets assume you are in the stock market, as this actually seems to be a more fun solution. I would go with a URL scheme format since you want to pass the quiz around via emails or w/e.

what this is means is that you will pass around a url that will launch your app

The url would look something like this:

`quizzer://question1/question2/question3

or something similar, you can basically do it any way you want

you need to add a key into your info.plist to describe the scheme, so this would go into it

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>quizzer</string>
            </array>
        </dict>
    </array>

Note, this can all be done in xcode, I don't use xcode anymore though... soo, yea

Ok, now whenever someone clicks on a URL that is formatted like above, your app will be launched and the app delegate will receive the message.

next, you need to implement this app delegate method

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{
  // Do something with the url here
}

there, now you can build w/e you want from the URL

METHOD 2: K, now we can assume you're in the jailbroken market. The easiest way i see is using a NSDictionary with the functions of

[NSDictionary dictionaryWithContentsOfFile:(NSString *)path];

and

[dictionary writeToFile:(NSString *)path atomically:(BOOL)atomically];

Note, the reason jailbroken is part of this is if you want to import the quiz from an email attachment. You would have to know the location of the attachment, which would probably be outside your sandbox, and then grab the info. This is something you cant do if you're not jailbroken.

If you have some other method of getting the file into your app's directory (server downloads or something similar), then these functions will be perfect for the task regardless of being jailbroken or not.

That would be for the importing exporting... i think that was the main part of your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜