I have the following code to send a URL
through AirDrop
:
NSString* selfUrlScheme = [[[[[[NSBundle mainBundle]
infoDictionary]
valueForKey:@"CFBundleURLTypes"]
objectAtIndex:0]
valueForKey:@"CFBundleURLSchemes"]
objectAtIndex:0];
NSURL* schemeURL = [NSURL URLWithString:
[NSString stringWithFormat:
@"addList:%@,%@",
self.list.uniqueID,
selfUrlScheme]];
NSArray *objectsToShare = @[schemeURL];
controller = [[UIActivityViewController alloc]
initWithActivityItems:objectsToShare
applicationActivities:nil];
// Exclude all activities except AirDrop
NSArray *excludedActivities = @[UIActivityTypePostToTwitter,
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
[self presentViewController:controller animated:YES completion:nil];
The recipient then gets the following message:
Is it possible to change the text of the URL
found after 'X would like to share' to something more user friendly like 'X would like to share a list with you'? Thanks in advance!
EDIT
I now have this but it still produced the same result above:
AirDropCustomURL *container = [[AirDropCustomURL alloc] initWithUrl:schemeURL];
NSString *message = @"a list";
controller = [[UIActivityViewController alloc] initWithActivityItems:@[message, container] applicationActivities:nil];
@interface AirDropCustomURL : NSObject <UIActivityItemSource>
@property (strong, nonatomic) NSURL *url;
@property (strong, nonatomic) UIImage *productImage;
- (id)initWithUrl:(NSURL *)url;
@implementation AirDropCustomURL
- (id)initWithUrl:(NSURL *)url {
if (self = [super init]) {
_url = url;
}
return self;
}
#pragma mark - UIActivityItemSource
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
//Because the URL is already set it can be the placeholder. The API will use this to determine that an object of class type NSURL will be sent.
return self.url;
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
//Return the URL being used. This URL has a custom scheme (see ReadMe.txt and Info.plist for more information about registering a custom URL scheme).
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
return nil;
} else {
if ([activityType isEqualToString:UIActivityTypeAirDrop]) {
return self.url;
}
}
return nil;
}