I have an app that has a share button. This share button loads a UIActivityViewController for sharing to Facebook, Twitter, email, text message, etc.
It used to work fine, and I think it still works fine on the simulator, but on devices, the view controller appears with all the right options, and if you click on one, either nothing happens, or if it's Mail, the mail modal view loads and then dismisses itself. Then I get my log "Activity was not performed.", which is when the completion block returns false for completed but the activityType was not null. So it is recognizing the selection, but it isn't loading the activity into the view for some reason
I have checked the stuff I'm trying to share, even replaced it with dummy stuff (as shown below), still no luck. I am using a normal device, I have my Twitter, Mail, and Facebook accounts set up, texting works too. The only thing that works is copy (i.e. when you copy the share contents to the clipboard). In other apps on the same device, the UIActivityViewController and the loading of selected activities works just fine. Same issue observed on other devices running the app as well.
Really don't understand what the issue is here. Very perplexing! Any help or suggestions of things to try would be much appreciated. I don't see any way to debug this issue.
Here's the code: (note I tried removing the image as well, no luck)
- (void)shareTapped {
NSString *shareText = #"Testing";//[self shareText];
NSURL *url = [NSURL URLWithString:#"http://www.google.ca"]; //[self shareURL];
NSArray *activityItems = [NSArray arrayWithObjects:shareText,url, self.shareImage, nil];
UIActivityViewController *shareDrawer = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
shareDrawer.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypePrint];
shareDrawer.completionHandler = ^(NSString *activityType, BOOL completed) {
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.");
}
}
NSString *result = completed ? #"success" : #"fail";
if (activityType == NULL) {
result = #"dismissed";
}
};
[self presentViewController:shareDrawer animated:YES completion:nil];
}
OK, by process of elimination I finally narrowed down the culprit:
I have a custom UISegmentedControl with a custom font for the text and I manually adjusted the content offset to make it appear properly. Although I have removed these lines and the segmented control actually looks fine.
Here's the code (I've confirmed that it's all three lines that cause the problem)
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(4, 0) forSegmentType:UISegmentedControlSegmentLeft barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(0, 0) forSegmentType:UISegmentedControlSegmentCenter barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setContentPositionAdjustment:UIOffsetMake(-4, 0) forSegmentType:UISegmentedControlSegmentRight barMetrics:UIBarMetricsDefault];
Now, seeing as the views that popup after you select a share option DO NOT HAVE SEGMENTED CONTROLS in them, I have no clue why this would cause this problem. But it definitely works now that I removed it.
Thanks for those of you who attempted to help. Of course, there's no way you could have possibly guessed this was the issue. Chances are pretty low that anyone would ever encounter this problem in the first place, since adjusting the content position is probably fairly rare.
To debug this issue I followed the following steps:
I tested if the issue had something to do with the properties on the UIActivityViewController that I was setting, or the activity items I was sharing. It did not.
I tested if UIActivityViewController worked properly when called from a different view controller inside my app. It did not.
I made a blank view controller with a button that causes a generic UIActivityViewController to show on press of a bar button. I made that my root view. That worked, thus showing that it was an isolated issue.
Instead of making that view controller the root of my app, I pushed it from my normal main view. It no longer worked, thus determining that the problem probably had something to do with my main view.
I commented out all the code in viewDidLoad, viewDidAppear, and viewWillAppear, except for adding a button to the nav bar which would load my sharing test. That worked. Then I uncommented viweDidAppear and viewWillAppear, still worked. So I uncommented chunks of viewDidLoad until I figured out exactly what the problem was.
What I learned: For weird problems like this (i.e. ones that seem like an iOS bug or something, but you can't find anyone posting about it), you should spend more time debugging before trying to post to stack overflow.
(I should really know this by now, but every new problem to debug feels like an exception to this rule)
Please comment below if you know why adjusting the content position of UISegmentedControl would mess up the sharing from UIActivityViewController even though those views don't contain segmented controls
Thanks
Had same issue too, here's what I done to overcome it.
I'd recommend adding the Social.framework to your Link Binary and using
SLComposeViewController *socialShare = [SLComposeViewController composeViewControllerForServiceType:shareType];
Where the shareType can be SLServiceTypeFacebook or SLServiceTypeTwitter.
I created a UIAlertview pop-up to show the share options for the user
UIAlertView *social = [[UIAlertView alloc]initWithTitle:#"Share" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Twitter", #"Facebook", #"Email", nil];
and depending on which one they picked (using the UIAlertview Delegate methods) then the content can be shared accordingly, and it's a great alternative to UIActivityViewController.
Hope this suggestion helps, cheers, Jim.
Related
I've implemented AirPrinting from my app but I'm facing a strange issue. Whenever the print dialog appears, there are no Cancel or Done/Print buttons displayed, as shown in the following image.
The code I'm using is as follows:
if ([UIPrintInteractionController canPrintURL:pdfUrl]) {
UIPrintInfo *aPrintInfo = [UIPrintInfo printInfo];
aPrintInfo.outputType = UIPrintInfoOutputGeneral;
aPrintInfo.jobName = [NSString stringWithFormat:#"%#-PRINT",[[NSUserDefaults standardUserDefaults] stringForKey:#"Kiosk ID"]];
UIPrintInteractionController *aPrintController = [UIPrintInteractionController sharedPrintController];
aPrintController.showsNumberOfCopies=YES;
aPrintController.showsPaperSelectionForLoadedPapers=YES;
aPrintController.printingItem = pdfUrl;
aPrintController.printInfo = aPrintInfo;
[aPrintController presentAnimated:YES completionHandler:NULL];
}
Does anyone have experience with this problem and know how to rectify? What's really odd is that the actions for these hidden buttons still work; so if I tap where the print button should be, it'll print and likewise I can close the dialog by tapping the top left where the Cancel button should be.
Cheers!
p.s using latest version of IOS 11, issue occurs in simulator and on device.
[Edit] I've just now tested a print example from Apple found at
https://developer.apple.com/library/content/samplecode/PrintBanner/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013422-Intro-DontLinkElementID_2
and although the code to bring up the AirPrint dialog are very similar (more-so after I tweaked a few bits of my code) the demo code worked as expected (buttons visible) while my code still does not. Very confusing.
[Edit 2] Using the code sample above in a fresh project works as expected too. Yet, in my full app, it does not. Does anyone have experience as to why that my be? Are system dialogs affected by the size of the app perhaps? Doesn't seem likely, but there is definitely something awry with my app using this code that isn't obvious.
[Edit 3] I enhanced the fresh project by incrementally introducing the same elements from my main project, going as far as bringing in the same Pods and setting up the same UI structure, and adding UIImage elements. It did not have the exact same number of views, and those were not doing the same things as my main project, but the memory usage was similar. And yet still, it worked. Are workspace corruptions a thing in Xcode, something behind the scenes not represented in any UI that might explain this?
[Edit 4] I just created a completely new project, reinstalled all the pods, then moved my source files from my original project to the new project. Quell surprise, the issue still remains in the new project.
[Edit 5] Solved! I finally found the issue thanks in part to the tip from the accepted answer below. It was due to having a global tint colour set to Clear, but also having individual Views within each controller also setting the tint colour to clear. This affected the dialog being shown and as such the buttons were invisible. Once I changed the Views to have an actual colour for the Tint property the print dialog buttons were once again visible.
There is no direct issue with UIPrintInteractionController code. As you mention click of done and cancel buttons are working as expected. The only problem is visibility of buttons.
Try changing navigation bar tint color before presenting print controller.
self.navigationBar.barStyle = UIBarStyle.Black
self.navigationBar.tintColor = .black
Note:- I don't have your code. This is only one of the problems and solution related to your issue.
I have also used your code and it is working as expected it has cancel and print button in iOS 11 also. Here is the code
([UIPrintInteractionController canPrintURL:self.pdfUrl]) {
UIPrintInfo *aPrintInfo = [UIPrintInfo printInfo];
aPrintInfo.outputType = UIPrintInfoOutputGeneral;
aPrintInfo.jobName = #"test job";
UIPrintInteractionController *aPrintController = [UIPrintInteractionController sharedPrintController];
aPrintController.showsNumberOfCopies=YES;
aPrintController.showsPaperSelectionForLoadedPapers=YES;
aPrintController.printingItem = self.pdfUrl;
aPrintController.printInfo = aPrintInfo;
[aPrintController presentAnimated:YES completionHandler:NULL];
}
Please check if pdfUrl is having valid URL, also in UI pdf should load if it is a valid url.
Below is the url which I am using
self.pdfUrl = [NSURL URLWithString:#"http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"];
Edit 1:-
Attaching the screen shot
I have a LaunchScreen.storyboard which serves as the launch screen file. In this storyboard is a view controller with the class LaunchViewController.
In my LaunchViewController.m file I changed the view's background color and added a label with the FB shimmering effect (https://github.com/facebook/Shimmer).
_shimmeringView = [[FBShimmeringView alloc] init];
_shimmeringView.shimmering = YES;
_shimmeringView.shimmeringBeginFadeDuration = 0.3;
_shimmeringView.shimmeringOpacity = 0.3;
[self.view addSubview:_shimmeringView];
_logoLabel = [[UILabel alloc] initWithFrame:_shimmeringView.bounds];
_logoLabel.text = #"Shimmer";
_logoLabel.font = [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:60.0];
_logoLabel.textColor = [UIColor whiteColor];
_logoLabel.textAlignment = NSTextAlignmentCenter;
_logoLabel.backgroundColor = [UIColor clearColor];
_shimmeringView.contentView = _logoLabel;
But when I ran it there's only an empty white background displayed as the launch screen. Also I find that he LaunchViewController looks fine when used as a regular view controller. How to make it display the same effect when used as launch screen?
You can't use code inside a launch view controller nib. Whether it is a storyboard or a separate nib. The code is not executed. The only thing that works is what is in InterfaceBuilder like auto layout and stuff. No code is loaded. This would defeat the purpose of using a launch file. The launcfile is loaded before the app has had chance to load.
No app, no code. Only the launch file.
I've had similar problems, and based on your code, it may be similar to mine. First off, I don't understand your question as much as I would like to. You said, "The LaunchViewController works fine when not used as launch screen." Does that mean that it looks the way you want it to look like when viewing on Xcode, but not on the simulator? I will try to provide possible solutions, and some trouble-shooting tips.
It could be something as simple as your background(or something) is at the front of the screen, blocking the rest. If so, you have to reconfigure the order of your items on your launch screen in your xib file in your application.
It could be an error on your part. Some of my programmer friends develop their launch screens using the Xcode interface: I find that easier to use, and it may have less errors.
It could be an issue with the iOS simulator. This is not likely to be true, but it could be. Try running the app on your device and see if it is fine there.
Troubleshooting: In order to trouble shoot your code, comment out your code, and load in all the elements of your launch screen one at a time, checking the iOS simulator and the console in between. You will eventually find the problematic code, and be able to fix it. From looking at your code, I don't see anything wrong (but don't take my word on it, I'm not familiar with coding the launchscreen/storyboard in swift. Good luck, and I hope my tips work. Also, if your launch screen is appearing fine inside Xcode, it is a programming error or an error on the iOS simulator. A picture or a description of your launch screen could also help future people who will answer this question.
I am trying to use the iOS file picker to select text files but when I instantiate and present (modally) a UIDocumentMenuViewController or a UIDocumentPickerViewController the UI takes a while to show up.
This is the code I tried to use for the UIDocumentMenuViewController the one for the UIDocumentPickerViewController would be fairly similar:
UIDocumentMenuViewController *menuVC = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:#[(NSString *)kUTTypeText] inMode:UIDocumentPickerModeOpen];
menuVC.delegate = self;
[self presentViewController:menuVC animated:YES completion:nil];
If I try to call this code 3 or more times then the lag disappears.
I understand that when working with iCloud documents there are synchronous operations that takes time but I didn't find a way to kind of preload that so by the time I present the view controller it happens instantly. I even tried to instantiate the view controllers much before presenting them, but the initialisation doesn't seam to be the bottleneck.
Did anyone experienced the same problem?
It turns out the problem was related to using appearance on a UISegmentController with a custom Font. It may be related to other UIKit controls as well.
Here the way I reproduced it on a clean project:
NSDictionary *attributes = #{NSFontAttributeName: [UIFont fontWithName:#"Pacifico" size:16]};
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
I filed a radar. Please go and dupe, especially if you find this is affected by other appearance calls.
My app allows the user to link other people within the app to entries in the contact book, and if one doesn't exist add a new one. I accomplish this by presenting an ABPeoplePickerNavigationController with an added button on the top for "Add Contact" which pushes an ABNewPersonViewController.
The problem I have is this functionality works perfectly in iOS 6, but completely fails to work properly in iOS 7. Clicking the "Done" button does absolutely nothing, and clicking "Cancel" simply stops the fields from being editable.
Has anyone encountered something like this and know how to fix it? Is this a known issue (Google search returned nothing useful"
Same problem for me.
My code was as follows,
ABNewPersonViewController *npvc = [[ABNewPersonViewController alloc] init];
npvc.view.backgroundColor = [UIColor colorWithRed:0.188 green:0.545 blue:0.016 alpha:1.0];
After I removed “npvc.view.backgroundColor =…”, it works fine.
Probably the structure of ABNewPersonViewController underneath has changed, so we are not allowed to set its background color.
I use a UIActivityViewController with valid activities in the activityItems (NSArray).
UIActivityViewController* activityController=[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
I have a problem with the appearance of the UIActivityViewController both in the simulator and on the iPhone itself. If I click 'Mail' then a mail form pops up that displays its title 'New message' directly over the statusbar (can't show you a picture 'cause I lack 'reputation'?) ending up with text written over info in the status bar.
The same happens with the message-activity. I think that the things I do are pretty basic and don't even offer the opportunity to mess things up. So what can be the reason that this happens? Or better: how can I prevent this from happening?
(Screenshot of the problem.)
Simple solution what worked for me is to embed view in Navigation Controller.
If you are using Storyboard you can try this.