#import <Foundation/Foundation.h>

@interface RemotePreferences : NSObject {
NSMutableData *incomingData;
}

@end

@implementation RemotePreferences

-(id)init {

self = [super init];

if (self) {

NSURL *url = [NSURL URLWithString: @"http://example.com/configs.plist"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
__unused NSURLConnection *fetchConn = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];

}

return self;

}

- (void)connection:(NSURLConnection *)sender didReceiveData:(NSData *)data {

if (!incomingData) {
incomingData = [[NSMutableData alloc] init];
}

[incomingData appendData:data];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)sender {

NSDictionary *prefsDict = [[[NSDictionary alloc] init] autorelease];
prefsDict = [NSPropertyListSerialization propertyListFromData:incomingData mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];

[[NSUserDefaults standardUserDefaults] registerDefaults:prefsDict];

// NSLog(@"NSUserDefaults dump: %@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);

}

- (void)connection:(NSURLConnection *)sender didFailWithError:(NSError *)error {
NSLog(@"connection failed: %@", [error localizedDescription]);
}

-(void)dealloc {
FuncLog();

[super dealloc];

[incomingData release];
incomingData = nil;

}

//- (NSURLRequest *)connection:(NSURLConnection *)c willSendRequest:(NSURLRequest *)req redirectResponse:(NSURLResponse *)res {}
//- (void)connection:(NSURLConnection *)sender didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)ch {}
//- (NSCachedURLResponse *)connection:(NSURLConnection *)sender willCacheResponse:(NSCachedURLResponse *)cachedResponse{}

@end

Sorry, the comment form is closed at this time.

© 2012 James Border Suffusion theme by Sayontan Sinha