我正在使用 Airdrop 发送自定义 URL,以使我的应用程序在其他设备上打开并显示相关信息。
它工作正常,但在接收设备上看起来真的很难看,因为他们收到一条消息,引用 URL 作为正在发送的东西,例如schemename://123456
. 有没有办法让消息看起来更好看,或者让接收设备告诉你它想在哪个应用程序中打开信息,而不是显示看起来神秘的 URL?
制作一个与 UIActivityItemSource 确认的自定义对象
@interface LAAirDropCustomUrl : NSObject <UIActivityItemSource>
@property (strong, nonatomic) NSURL *url;
@property (strong, nonatomic) UIImage *productImage;
- (id)initWithUrl:(NSURL *)url;
@end
@implementation LAAirDropCustomUrl
- (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;
}
- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size
{
//Add image to improve the look of the alert received on the other side, make sure it is scaled to the suggested size.
return self.productImage;
}
这篇 Eventbrite 工程帖子描述了一种实现预期任务的潜在方法。
帖子中有一个示例项目https://engineering.eventbrite.com/setting-the-title-of-airdrop-shares-under-ios-7/
帖子的快速摘要:
使用只能由您的应用打开的自定义扩展名(文件类型)将 URL 保存在文件中。Airdrop 收件人将在您的应用程序中打开该文件(如果他们已安装该文件),或者将被要求从 AppStore 安装您的应用程序。