Receiving NSString on my apps by using AirDrop

504 views Asked by At

Is there anyone who know how to receive NSString sent over AirDrop on my app? So far, my app can send NSString over AirDrop. But I don't know how to open the NSString I send over Airdrop by using my app.

@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

There are 1 answers

0
ccjensen On

Look into using UIActivityItemSource to send the NSString as NSData + a custom UTI for your app. Basically define a new file format, that could be as simple as NSString encoded as UTF8 data, and then on the receiving side in your app code you convert this back into an NSString. The AirDrop sample code will likely be helpful.