My problem is with the groundcontrol example. When I use the default url to get the message greeting, it works, but when I change it to the URL of my plist on my own server. No message comes up, it is just blank.
The line I am changing to my own server is the following:
static NSString * const kGroundControlDefaultsURLString =
@"http://ground-control-demo.herokuapp.com/defaults.plist";
I have tried downloading the exact plist file and uploading it to my server, but that doesn’t even work.
I noticed one difference when going to the file in the browser, on the example link above it would automatically download, but on my own server it would open in the server.
So then I tried adding the following to my .httaccess file to make the file on my own server also automatically download, which it did after adding this, but also did not work from app.
<FilesMatch "\.(?i:plist)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
the debugger spits out nothing when it fails, when it works (from the example URL) it spits out the following:
2012-11-11 17:18:40.163 GroundControl Example[13804:f803]
NSUserDefaultsDidChangeNotification: NSConcreteNotification 0x68b9e40 {name =
NSUserDefaultsDidChangeNotification; object = <NSUserDefaults: 0x6e83400>}
So this is my problem, and essentially what I would like to be able to do is get the file working just by uploading a .plist file to my server and use ground control to work with it.
Thanks for the help Stackoverflow.
Here is some of the groundControl code if that helps..
-from AppDelegate.m
static NSString * const kGroundControlDefaultsURLString = @"http://ground-control-demo.herokuapp.com/defaults.plist";
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSUserDefaults standardUserDefaults] registerDefaultsWithURL:[NSURL URLWithString:kGroundControlDefaultsURLString]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
-from ViewController.m
@implementation ViewController
- (void)updateValues {
self.greetingLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"Greeting"];
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:NSUserDefaultsDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
NSLog(@"NSUserDefaultsDidChangeNotification: %@", notification);
[self updateValues];
}];
[self updateValues];
}
SOLUTION
Based on Jake Bonham’s comment,
Changing this line in my .httaccess file on my server worked, with GroundControl classes and all.
ForceType application/octet-stream
octet-stream to x-plist
<FilesMatch "\.(?i:plist)$">
ForceType application/x-plist
Header set Content-Disposition attachment
</FilesMatch>
Also maybe this helped
Loading the plist into a dictionary first worked.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//THIS IS THE PART THAT I CHANGED
NSURL* url = [NSURL URLWithString:@"http://mydomain.org/defaults.plist"];
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:url];
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
//AND FINALLY LOAD dict INTO NSUserDefaults
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I just ran into this issue also. Logging out the error response said it was expecting type “application/x-plist” and got “application/octet-stream” from my saved .plist file.
Your solution removes the GroundControl classes. You are loading the url into a dict then saving that to user defaults. So it works. Just not using GroundControl.