4

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.

enter image description here

Any ideas would be appreciated.

Chris
  • 5,485
  • 15
  • 68
  • 130
  • I have created new project and added your above as action of one button event, and it is working perfectly fine with having navigation bar having cancel and post button. You can see screenshot at this link: https://drive.google.com/file/d/0B0FNcjA1N299NWdmZGZQWC1KbzA/view?usp=sharing – Mehul Thakkar Feb 01 '16 at 05:34
  • possibly version of fb might be making problem or fb account might be making problem. Otherwise your code is perfect.. as it is working in my case. – Mehul Thakkar Feb 01 '16 at 05:38
  • For status bar color and navbar colors, you should check this question on stackoverflow: http://stackoverflow.com/questions/19794317/modal-status-bar-and-navigation-bar-text-colors-from-uiactivityviewcontrollers-i – Mehul Thakkar Feb 01 '16 at 05:46
  • Thanks @MehulThakkar - I am not actually concerned about the color of the status bar, I just thought it might be a clue about the problem. I also created a new app and the code worked correctly - so now I am left thinking it is a problem in my app, but I do not know what. – Chris Feb 01 '16 at 14:33
  • Can you please check that... have done something with this [[UINavigationbar appearance] blah.. blah..], Possibly it might be due to that.. otherwise i am not thinking that there is any problem with your code – Mehul Thakkar Feb 01 '16 at 19:49
  • That fixed it, I have `[[UINavigationBar appearance] setHidden:YES]` in the App Delegate - Is there a way I can make the Navigation Bar visible on the Facebook modal view without having to `setHidden:NO` ? @MehulThakkar – Chris Feb 01 '16 at 20:31
  • If you are doing anything on [UINavigationBar appearance], then it is going to be applied on all the navigationbars that are going to be appeared in our app. You can individually customize it, but you should have the object for it.. now here, in this case.. we cant have viewcontroller object for fb's view which is getting presented\ – Mehul Thakkar Feb 02 '16 at 04:59

2 Answers2

5

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 

          }];
Vizllx
  • 9,135
  • 1
  • 41
  • 79
  • Excellent work bro... You solve a great problem for me.I was facing this issue from last two months :) – Naveed Khan Jan 30 '17 at 08:20
  • 1
    setCompletionHandler is deprecate in iOS 8+, it updates to setCompletionWithItemsHandler. [activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { [[UINavigationBar appearance] setHidden:YES]; }]; – Yao Li Nov 10 '17 at 19:57
  • works for urban airship too. Looks like framework writers have zero idea about vastness of scenarios their code must work in. – Anton Tropashko Dec 14 '18 at 11:25
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.

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81