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.
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
}];
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.
Related
I am seeing a very weird UI bug with the ABPeoplePickerNavigationController on iPad (in landscape) where when a user clicks the search bar in the PeoplePicker then subsequently cancels out, the keyboard is not resigned and the UI of the people picker gets all messed up. Here is a photo of the bug:
The ABPeoplePickerNavigationController is presented in a modal form sheet using the following code:
- (void) openAddressBook
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.delegate = self;
[picker setModalPresentationStyle: UIModalPresentationFormSheet];
[self presentViewController:picker animated:YES completion: nil];
}
The UI is as expected until a user taps on the search field, which brings up the keyboard, then cancels out of the search field, which does not resign the keyboard as it does on iPhone. Also, when the user scrolls the contacts list in this mode, all of the letter headers (i.e. the A header) are pinned where the A header is currently, not at the top of the view directly under the search bar.
Is there a reason that the keybaord is not being resigned here?
I am having difficulty debugging this as the ABPeoplePickerNavigationController is not subclassable, so any help would be greatly appreciated!
That is how UIModalPresentationFormSheet works: by default, it does not dismiss the keyboard when first responder is resigned. Clearly ABPeoplePickerNavigationController is not expecting to be used this way. My suggestion: don't do that. Use a popover or a normal presented view. (My experience is that a popover looks better.)
use [self.view endEditing:YES]; when you are done
I've implemented an Action (Share) button in a toolbar of my application. Upon tapping it, the action sheet - UIActivityViewController - pops up as expected, but it changes my previously black status bar text to white automatically. How do I prevent that so that it remains black? Thanks!
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[self.pasteboardField.text] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
set this line into your info.plist file:
View controller-based status bar appearance to NO
I got this code that brings up the native "share" view where the user can post to facebook/twitter etc... There is a completion block, but this only get´s called when the VC shows itself, I need to know when it dismisses. Cause my app has different View Controllers for landscape / portrait mode, and I do not want to dismiss the view if the user rotates and the UIACtivityViewController is on screen.
I send a notification when the shared button is pressed to not dismiss the current view if user rotates the device. All i need now, is to know when it´s dismissed so I can reenable the function
- (IBAction)shareButtonPressed:(UIButton *)sender {
// Notify that another view is on screen to allow rotation without view disapearing.
[self sendNotificationWithName:#"landscapeViewHasPopupActive" andObject:#"empty string"];
NSString *message = #"Hello World!";
UIImage *imageToShare = [UIImage imageNamed:#"Icon.png"];
NSArray *postItems = #[message, imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postItems
applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:^() {
}];
// Is showing landscape set to NO, and YES when this view disapears
}
In ios6 storyboards, there is a thing called an unwind segue. Add a method to the presenting controller to verify if unwind can/will happen. Check with google.
The same view controller that called the – presentViewController:animated:completion: method has it's counterpart: the – dismissViewControllerAnimated:completion: method.
When you want to dismiss the activityVC controller call the – dismissViewControllerAnimated:completion: method. Use the 'completion' block to execute the code you want when the view controller is dismissed.
Hope this helps!
I use a UIActivityViewController inside a Container View. I want to share some text by using Email, twitter and facebook. While the last two works perfectly i have a problem with Email. The problem is that the composer view doesn't dismisses either by canceling the event nor by trying to send it! When the ActivityView appears i get the following message:
Launch Services: Registering unknown app identifier com.apple.mobilemail failed
Launch Services: Unable to find app identifier com.apple.mobilemail
This is strange since there is really no problem with the app identifier and i can share text with email, using ActivityViewController in other view controllers (when not in a container view).
My code, below:
- (void)openBtnTouched {
NSString *alertTitleString = [[[GlobalVariables sharedInstance].alertsArray objectAtIndex:self.selectedIndex]objectForKey:#"alertTitle"];
NSString *alertMsgString = [[[GlobalVariables sharedInstance].alertsArray objectAtIndex:self.selectedIndex]objectForKey:#"alertMessage"];
UIActivityViewController *activity;
activity = [[UIActivityViewController alloc] initWithActivityItems:#[alertTitleString,alertMsgString] applicationActivities:nil];
activity.excludedActivityTypes = #[
UIActivityTypeMessage,
UIActivityTypePostToWeibo,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard];
activity.completionHandler = ^(NSString *activityType, BOOL completed){
NSLog(#"Activity Type selected: %#", activityType);
if (completed) {
NSLog(#"Selected activity was performed.");
} else {
if (activityType == NULL) {
NSLog(#"User dismissed the view controller without making a selection.");
} else {
NSLog(#"Activity was not performed.");
}
}
};
[self presentViewController:activity animated:YES completion:NULL];
}
I'm not sure whether your app is designed for iPhone, iPad, or both, but Apple are very specific about how to display a UIActivityViewController. From their documentation:
When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
If you're displaying it in some other way (i.e, in a container view controller) you may well encounter this sort of weird behavior. I'd recommend you display the activity view controller as recommended by Apple.
I am currently doing some updates for an iOS application. For the update I am going to take advantage of iOS6 capabilities. I am using a UIActivityViewController to get this done as well as some custom UIActivity activities. The main issue I am having is that there is no "Cancel" or "Close" button. The only way you can exit out of the activity view is if you either post something to a social network, or act like you are going to and then cancel.
NSArray* dataToShare = [[NSArray alloc] initWithObjects:#"blah", nil];
// Custom activities are allocated here
NSArray* customActivities = [[NSArray alloc] initWithObjects:activities, nil];
NSArray* excludedActivities = [[NSArray alloc] initWithObjects:exclusions, nil];
activityController = [[UIActivityViewController alloc] initWithActivityItems:formatArray applicationActivities:customActivities];
activityController.excludedActivityTypes = excludedActivities;
activityController.modalPresentationStyle = UIModalPresentationFormSheet;
[[UIApplication sharedApplication].keyWindow addSubview:self.view];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:activityController.view];
[self presentViewController:activityController animated:YES completion:^{ closureCode
}];
This does everything that I need inside of the activity controller in terms of networking content, I just don't have a close button. I don't know if it is the same issue but when the view disappears if I try to bring one up my "Share" menu again it tells me
<UIActivityViewController: 0x1e0db7d0> on <ShareDelegate: 0x1e048490> which is already presenting <UIActivityViewController: 0x21b1d4f0>
Thoughts? Thanks in advance!
*I am using:
iPad 2
Objective-C/C++
XCode 4.5
iOS6
From the docs for UIActivityViewController (emphasis is mine):
When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
On the iPad, the popover will be cancelled by the user tapping outside of the popover.
On the iPhone/iPod touch, the modal view controller will be shown with a cancel button.
In short, don't use a form sheet on the iPad.