开发者

Suggestions needed for architecting my code

Background

I'm writing an part of my app that has no UI. It sits in the background watching what you do and timing your work.

There should be no overlapping times, and there should be no breaks in the time data. If there are either of these things, the app has a bug somewhere and I need to be notified.

What I Want

A class called JGDataIntegrityController that does the following:

  1. Check the data store for duplicate times. Scan since the last Duplicate Report Date stored in NSUserDefaults.

  2. If duplicate times are found, build a report.

  3. Send the report.

    If the sending isn't successful, then exit. Otherwise continue.

  4. Remove the duplicates

  5. Update the last Duplicate Report Date in NSUserDefaults

  6. Repeat the above for data breaks.

What I've Got

I've made a base class that does all the hard work of sending the report.

Class Diagram http://synapticmishap.co.uk/ReportClasses.jpg

JGReportSender has the following code:

-(void)postReport:(NSString *)report {
    NSMutableDictionary *form = // Dictionary Holding Report;
    NSURLRequest *request = [NSURLRequest requestWithURL:@"http://postURL" postForm:form];
    [NSURLConnection connectionWithRequest:request delegate:self];
}

Where I'm Getting Stuck

What should I do when the report has been sent?

The delegate methods:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError*)error

are called when the report has been sent. But how should I communicate with JGDataIntegrityController?

My Crap Idea

My idea is to have a reportStatus NSNumber property in JGReportSender. Then when the delegate methods get called, this is updated.

reportStatus = 1 means "report sent OK".

reportStatus = 2 means "problem sending report".

Then I could add an observer for reportStatus for JGDataDuplicateReportSender and JGDataBreakReportSender. This would then handle the report sending error or continue on.

Any Good Ideas?

I get the feeling this is a really messy way of doing this. I also feel like I'm overlooki开发者_JAVA技巧ng something really obvious.

Any ideas how to do this in a neat way?

Update

I totally forgot to mention - this will be a 100% opt in feature. It'll be disabled by default. It'll also have 3 levels of privacy - from "a data break occurred" through to "a data break occurred after this application was active with this document path". And the reports will also be anonymous.

I'm conscious of all the privacy concerns - this is so I can make the software better, not so I can spy on people!


Give the report sender a delegate property and protocol, with at least two methods: reportSenderDidSucceed: and reportSender:failedWithError:. The report sender will send the latter message from its connection:didFailWithError: method, passing along the error object it got.

I do hope you'll make this feature optional. Expect lots of angry/curious email from users (not to mention public warnings of “don't use this app because it phones home” on web pages) if you don't.


Just a quick note to say if anyone wants a good tutorial on implementing your own delegates as Peter is suggesting I do, I found this one:

http://cocoadevcentral.com/articles/000075.php

Check it out. It's excellent!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜