使用AirDrop在我的应用上接收NSString

时间:2013-12-09 03:58:53

标签: ios objective-c ios7 nsstring airdrop

有没有人知道如何在我的应用程序上接收通过AirDrop发送的NSString?到目前为止,我的应用程序可以通过AirDrop发送NSString。但我不知道如何通过使用我的应用程序打开我通过Airdrop发送的NSString。

@interface ComposeViewController ()

@end

@implementation ComposeViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

}


-(BOOL) textFieldShouldReturn: (UITextField *) textField
{
    [textField resignFirstResponder];

    return YES;
}

- (IBAction)sendButton:(id)sender {

    NSString* message= self.inputTextField.text;
    NSLog(@"you type: %@", self.inputTextField.text);
    // enabling airdrop
    UIActivityViewController *controller = [[UIActivityViewController alloc]        initWithActivityItems:@[message] applicationActivities:nil];

// Exclude all activities except AirDrop.
NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
                                UIActivityTypePostToWeibo,
                                UIActivityTypeMessage, UIActivityTypeMail,
                                UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
                                UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
                                UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;

// Present the controller
[self presentViewController:controller animated:YES completion:nil];

//[self.readTextView setText:self.inputTextField.text];

}

1 个答案:

答案 0 :(得分:1)

使用UIActivityItemSource将NSString作为NSData +发送给您的应用程序的自定义UTI。基本上定义一种新的文件格式,可以像编码为UTF8数据的NSString一样简单,然后在应用程序代码的接收端将其转换回NSString。 AirDrop sample code可能会有所帮助。