gpt4 book ai didi

ios - 在 IOS 中自定义 AirDrop 警报描述

转载 作者:IT王子 更新时间:2023-10-29 08:16:14 24 4
gpt4 key购买 nike

我有以下代码通过 AirDrop 发送 URL:

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];

收件人随后会收到以下消息:

enter image description here

是否可以将“X would like to share”之后找到的 URL 的文本更改为更用户友好的内容,例如“X would like to share a list with you”?提前致谢!

编辑

我现在有了这个,但它仍然产生了与上面相同的结果:

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;
}

最佳答案

您必须实现一个符合 UIActivityItemSource 协议(protocol)的类。这里有一个很好的例子:https://developer.apple.com/LIBRARY/IOS/samplecode/sc2273/Introduction/Intro.html .请特别查看 APLCustomURLContainer。实现 URL 容器类后,您可以将其与字符串(这将是您的自定义消息)一起添加到事件项中

MyURLContainer *container = [[MyURLContainer alloc] initWithURL:yourURL];
NSString *message = @"Your message";
UIActivityViewController activityController = [[UIActivityViewController alloc] initWithActivityItems:@[message, container] applicationActivities:nil];

编辑:

一开始我没有两部手机可以尝试,所以我只测试了 Facebook 和 Twitter 的正常工作,但是对于 AirDrop,我现在可以确认(经过一些测试后)它总是使用 NSURL 的 relativeString即使您覆盖了 NSURL 的该方法,共享也将不起作用,因此对于 AirDrop(FB 等其他事件都可以),无法使用当前的 SDK 更改该消息。

关于ios - 在 IOS 中自定义 AirDrop 警报描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20223107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com