Customize the AirDrop alert description in IOS

后端 未结 4 960
盖世英雄少女心
盖世英雄少女心 2021-02-02 14:19

I have the following code to send a URL through AirDrop:

NSString* selfUrlScheme = [[[[[[NSBundle mainBundle]
                                 


        
相关标签:
4条回答
  • 2021-02-02 14:31

    You need to follow the tutorial HERE. After the heading "A Quick Look at UIActivityViewController", i think thats exactly what you are looking for.

    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
    [self presentViewController:controller animated:YES completion:nil];
    
    0 讨论(0)
  • 2021-02-02 14:37

    This question has been posted a looong time ago. I tried @Ivan's answer as well as other answers in the post, however, they just do not work!

    What I have originally is the image on the left. I am sharing custom data via AirDrop and looked at the title that is generated by UIActivityController by default "data-3A4F9D...", orz. What I want to achieve is a more descriptive title so that it is more readable for the recipient (image on the right). It seems that it is extremely similar to your question (even though I am sharing NSData while you are sharing NSURL.

    Here is what I do, which works pretty well: implement the following UIActivityItemSource protocol within my UIActivityItemProvider.

    - (NSString *)activityViewController:(UIActivityViewController *)activityViewController
              subjectForActivityType:(NSString *)activityType
    {
            // This returning string is added to the email title
            return NSLocalizedString(@"CustomTitle", nil);
    }
    

    If you are still having this problem, feel free to give this a try and let me know how it works for you.

    0 讨论(0)
  • 2021-02-02 14:42

    Seems to me like it is using the description of the URL. I would try to subclass NSURL and override the description method to return something like @"a list". I didn't try it, but seems like it could work...

    EDIT: I found this question that looks to be the same as yours and it has an accepted answer: Airdrop: making a custom URL scheme be less ugly for recipient

    0 讨论(0)
  • 2021-02-02 14:49

    You'll have to implement a class conforming to the UIActivityItemSource protocol. There is a very nice example here: https://developer.apple.com/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];
    

    EDIT:

    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.

    0 讨论(0)
提交回复
热议问题