URL
我有以下代码可以发送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];
然后收件人会收到以下消息:
URL
是否可以将在“X 想分享”之后找到的文本更改为更用户友好的内容,例如“X 想与您分享列表”?提前致谢!
编辑
我现在有了这个,但它仍然产生了与上面相同的结果:
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;
}