如何将NSUserDefaults同步到Twitter消息中?

时间:2013-01-03 04:06:25

标签: iphone ios xcode twitter nsuserdefaults

我可以在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];

1 个答案:

答案 0 :(得分:1)

 [controller setInitialText:[[NSUserDefaults standardUserDefaults] valueForKey:@"savedstring"]];

如果你想从用户Defaults返回字典时需要字符串值,那么你可以使用JSON将它转换为字符串。