地面控制示例,在我的服务器上使用.plist



我的问题与地面示例有关。当我使用默认URL获取消息问候时,它可以正常工作,但是当我将其更改为自己的服务器上的PLIST时。没有消息出现,只是空白。

我更改为自己的服务器的行是:

static NSString * const kGroundControlDefaultsURLString =
@"http://ground-control-demo.herokuapp.com/defaults.plist";

我尝试下载确切的PLIST文件并将其上传到我的服务器,但这甚至行不通。

我注意到在浏览器中的文件时,在上面的示例链接上会自动下载一个区别,但是在我自己的服务器上它将在服务器中打开。

因此,我尝试将以下内容添加到我的.httaccess文件中以使我自己的服务器上的文件也自动下载,在添加此文件后确实会下载,但也无法从app中使用。

<FilesMatch ".(?i:plist)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

调试器在失败时什么也没吐出,当它起作用时(从示例URL)吐出以下内容:

2012-11-11 17:18:40.163 GroundControl Example[13804:f803] 
NSUserDefaultsDidChangeNotification: NSConcreteNotification 0x68b9e40 {name = 
NSUserDefaultsDidChangeNotification; object = <NSUserDefaults: 0x6e83400>}

所以这是我的问题,从本质上讲,我想做的就是通过将.plist文件上传到我的服务器并使用地面控件来使用该文件。

感谢您的帮助stackoverflow。

如果有帮助,这是一些景点代码。

-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];
}

解决方案

根据杰克·邦纳姆(Jake Bonham)的评论,

在我的服务器上使用的.httaccess文件中更改此行,使用了GroundControl类,

ForceType application/octet-stream   

八位字到X-Plist

<FilesMatch ".(?i:plist)$">
  ForceType application/x-plist
  Header set Content-Disposition attachment
</FilesMatch>

也许这有帮助

将PLIST加载到字典中。

- (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;
}

我也遇到了这个问题。记录错误响应表示它正在期望从我保存的.plist文件中获取"应用程序/x plist",并从我保存的.plist文件中获取"应用程序/octet-stream"。

您的解决方案删除了地面控制类。您将URL加载到dict中,然后将其保存到用户默认值中。因此起作用。只是不使用地面控制。

最新更新