在IOS中自定义AirDrop警报说明

编程入门 行业动态 更新时间:2024-10-28 18:25:39
本文介绍了在IOS中自定义AirDrop警报说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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:

是否有可能将X想要分享之后找到的网址的文字更改为更加用户友好的内容,例如X想要与您共享列表?提前致谢!

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!

编辑

我现在有这个但是仍然产生了相同的结果:

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

推荐答案

你必须实施符合UIActivityItemSource协议的类。这里有一个很好的例子: developer.apple .COM /图书馆/ IOS / samplecode / sc2273 /简介/ Intro.html 。请特别注意APLCustomURLContainer。实现URL容器类后,您可以将其与字符串一起添加到活动项目中(这将是您的自定义消息)

You'll have to implement a class conforming to the UIActivityItemSource protocol. There is a very nice example here: developer.apple/LIBRARY/IOS/samplecode/sc2273/Introduction/Intro.html. Take a look at the APLCustomURLContainer in particular. After you implement your URL container class you can add it to the activity items along with a string (which will be your custom message)

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更改该消息。

I didn't have two phones to try that out at first so I tested only for Facebook and Twitter where it's working correctly, but for AirDrop I can confirm now (after some testing) that it is always using the relativeString of NSURL and even if you override that method of NSURL the sharing won't work so for AirDrop (the other activities such as FB are OK) it is not possible to change that message with the current SDK.

更多推荐

在IOS中自定义AirDrop警报说明

本文发布于:2023-10-15 01:34:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   警报   IOS   AirDrop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!