As we know for the Facebook SDK we should provide the URL types and the FacebookAppID keys in the App Plist.
My question is how to store them programmatically without enter them manually in the plist, like in the UIApplicationDelegate method didFinishLaunchingWithOptions.
I try to set it using NSUserDefaults but it keep give this error:
No AppID provided; either pass an AppID to init, or add a string valued key with the appropriate id named FacebookAppID to the bundle *.plist'
I don't know why but I guess Xcode store the keys using NSUserDefaults in somewhere else the default app Plist.
Does anyone know how to fix this?
This seems to work for me, to set the App ID:
[FBSettings setDefaultAppID: @"123456789"];
I don't know if there is something similar for the URL types. However, I can imagine that registering URL types is something that iOS does when the app is installed, and so if that's the case it might need to be in the plist file and not in code.
For some reason it is not secure. It's very easy to get your app plist file and read all information. You should keep your app private key secure. But if you really want to do that, you can parse data from your plist file:
NSString *path = [[NSBundle mainBundle] pathForResource:@"yourPlistFileName" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];
NSLog(@"You app key is %@",[dict objectForKey:@"yourKeyFromPlist"]);
The easiest way to store something shared within all app is to use NSUserDefaults. But do not forget to call synchronize after you do any changes. Here is NSUserDefaults documentation. I don't think this is a good solution to write any data to your plist, but if you really want to, here is a code:
NSString* plistPath = nil;
NSFileManager* manager = [NSFileManager defaultManager];
if ((plistPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"yourPlistFileName.plist"]))
{
if ([manager isWritableFileAtPath:plistPath])
{
NSMutableDictionary* infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
[infoDict setObject:@"your key value" forKey:@"Your Key"];
[infoDict writeToFile:plistPath atomically:NO];
[manager setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] ofItemAtPath:[[NSBundle mainBundle] bundlePath] error:nil];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With