我可以在NSUserDefaults
消息中同步Twitter
数据吗?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Cancelled");
} else
{
NSLog(@"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:@""];
[controller addURL:[NSURL URLWithString:@""]];
[controller addImage:[UIImage imageNamed:@""]];
[self presentViewController:controller animated:YES completion:Nil];
}
我需要设置初始文本来接受nsuserdefaults,因为我有一些用户设置的借词。这是nsuserdefaults。
NSString *savestring =field.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savedstring"];
[defaults synchronize];
答案 0 :(得分:1)
[controller setInitialText:[[NSUserDefaults standardUserDefaults] valueForKey:@"savedstring"]];
如果你想从用户Defaults返回字典时需要字符串值,那么你可以使用JSON将它转换为字符串。