Facebook UIActivityViewController is Missing the C

2020-07-18 07:51发布

问题:

When my app opens the Facebook UIActivityViewController, there is no navigation bar at the top of the Facebook screen and there is no Cancel or Post button - the only way to exit the screen is to kill the app. Other apps that I look at have an additional navigation bar at the top of the Facebook screen, which holds the Cancel and Post buttons.

Here is the code I am using:

        NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com"];
        NSArray *activityItems = @[url];

        // Put together the UIActivityViewController
        UIActivityViewController *activityVC = [[UIActivityViewController alloc]
                                                initWithActivityItems:activityItems
                                                applicationActivities:nil];

        activityVC.excludedActivityTypes = @[UIActivityTypePrint,
                                             UIActivityTypeCopyToPasteboard,
                                             UIActivityTypeAssignToContact,
                                             UIActivityTypeSaveToCameraRoll,
                                             UIActivityTypeAirDrop,
                                             UIActivityTypePostToVimeo,
                                             UIActivityTypePostToFlickr,
                                             UIActivityTypeAddToReadingList];

        // Present the UIActivityViewController
        [self presentViewController:activityVC
                           animated:YES
                         completion:nil];

The Twitter, Email, and SMS screens all appear as expected. Facebook is the only one that is having problems.

Some other notes: I notice that when I open the Facebook Share on this app, the status bar turn black with white text. On another test app that I created, the status bar looks grayed-out with black text. Not sure why / what this points to, but might be a clue.

This problem seems to be app-wide, as I have 3 spots where sharing can be invoked, and it is happening in all 3 instances.

Attaching an image. There should be a Navigation bar above the "To: Public" toolbar.

Any ideas would be appreciated.

回答1:

I have created new app and copy pasted your code on button action. It is workiing perfectly. You can check image of it over here: https://drive.google.com/file/d/0B0FNcjA1N299NWdmZGZQWC1KbzA/view?usp=sharing

As per my knowledge, If you have done something with [UINavigationBar appearance] in your app, then and then only it makes the problem. Please check that.



回答2:

You can hide the navigation bar as per your requirement.

So, add the below code, if you want to show the navigation when UIActivityViewController is present and then hide it when UIActivityViewController is dismissed:-

//this will be called when the UIActivityViewController  will be dismissed, so we are hiding the navigation

[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
                [[UINavigationBar appearance] setHidden:YES];


        }];



//this will be called when the UIActivityViewController  will be shown, so we are enabling the navigation mean unhiding it.

[self presentViewController:activityVC animated:YES completion:^{
                 [[UINavigationBar appearance] setHidden:NO]

                  //you can also add code to customize status bar 

          }];