有没有人知道如何在我的应用程序上接收通过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];
}
答案 0 :(得分:1)
使用UIActivityItemSource将NSString作为NSData +发送给您的应用程序的自定义UTI。基本上定义一种新的文件格式,可以像编码为UTF8数据的NSString一样简单,然后在应用程序代码的接收端将其转换回NSString。 AirDrop sample code可能会有所帮助。