-1

有没有办法可以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];
4

1 回答 1

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

如果您想要从用户默认值返回字典的字符串值,那么您可以使用 JSON 将其转换为字符串。

于 2013-01-03T04:10:03.833 回答