アプリにメールから設定をインポートさせようとしています。これが機能する方法は、ユーザーが自分自身にファイルを送信することsettings.properties
です。これは実際にplist
は次のようになります
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Viewer</key>
<array>
<string>username</string>
<string>password</string>
<string>http://www.example.com</string>
<string>/example</string>
<string>urlparam=whatever</string>
</array>
</dict>
を使用してファイルを正しく開いて読み取ることができますが、既存のものを上書きせずにアプリのメイン Data.plist にNSLog
インポートし、インポートしたplist を Documents/Inbox フォルダーから削除する必要があります。dictionary
手がかりは素晴らしいでしょう:)
//編集
以下のコメントに基づいてメソッドを更新しました。ファイル Data.plist がアプリのドキュメント ディレクトリに既に存在する場合にのみ機能するようになりました。したがって、存在しない場合は作成してから、.properties ファイルに追加する必要があります。
これは私が現在使用しているコードです。
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (url){
NSDictionary *openedDictionary = [NSDictionary dictionaryWithContentsOfURL:url];
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
NSDictionary *originalDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSMutableDictionary *newDictionary = [originalDictionary mutableCopy];
for (NSString *key in openedDictionary) {
if (!newDictionary[key]) {
newDictionary[key] = openedDictionary[key];
}
}
[newDictionary writeToFile:plistPath atomically:YES];
}
NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtURL:url error:&error]) {
NSLog(@"error while deleting: %@", [error localizedDescription]);
}
return YES;
}