私の問題は、グラウンドコントロールの例にあります。デフォルトの URL を使用してメッセージ グリーティングを取得すると機能しますが、自分のサーバーの plist の URL に変更すると機能します。メッセージは表示されず、空白のままです。
自分のサーバーに変更している行は次のとおりです。
static NSString * const kGroundControlDefaultsURLString =
@"http://ground-control-demo.herokuapp.com/defaults.plist";
正確な plist ファイルをダウンロードしてサーバーにアップロードしようとしましたが、うまくいきません。
ブラウザでファイルに移動すると、1 つの違いに気付きました。上の例のリンクでは自動的にダウンロードされますが、自分のサーバーではサーバーで開かれます。
そこで、.httaccess ファイルに以下を追加して、自分のサーバー上のファイルも自動的にダウンロードするようにしました。
<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ファイルをサーバーにアップロードするだけでファイルを機能させ、地上管制を使用してそれを操作することです.
助けてくれてありがとう。
それが役立つ場合、ここにgroundControlコードの一部があります..
-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;
}
-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];
}
解決
ジェイク・ボーナムのコメントに基づいて、
サーバー上の .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;
}