UIDocumentInteractionController not transferring to target application - objective-c

My app is generating an image which I'm attempting to pass to Instagram using a document interaction controller and their hook. Oh, this is using iOS 5.1.
I have the UIDocumentInteraction action sheet showing up properly but the issue is that once the user select "open in Instagram" the sheet is dismissed and nothing happens.
The code:
// Method returns a path to the generated image
NSURL *finalCompositePath = [NSURL fileURLWithPath:[self generateFinalImage:#"instagram"]];
UIDocumentInteractionController *documentInteractionController;
NSURL *instagramURL = [NSURL URLWithString:#"instagram://camera"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:finalCompositePath];
documentInteractionController.UTI = #"com.instagram.exclusivegram";
documentInteractionController.delegate = self;
documentInteractionController.annotation = [NSDictionary dictionaryWithObject:#"Caption Test" forKey:#"InstagramCaption"];
[documentInteractionController presentOptionsMenuFromBarButtonItem:self.ShareButton animated:YES];
}
Thoughts?

UIDocumentsInteractionController shows iBooks but doesn't open it has the correct answer for apps using arc. UIDocumentInteractionController must be a property of the class.
BUT ALSO!!!
If you are supporting down to ios5, make sure the image you've saved is a type ".igo" (not .jpg or .png).
IOS6 will open it up in instagram, but IOS less than 6 will just dismiss the UIDocumentInteractionController without proceeding to instagram.

Related

How to stop AVAudioPlayer once we navigate from one view to into other view in iOS8?

I am fresher to iOS. I am using AVFoundation framework for AVAudioPlayer. This is used for running background sound when user enters into application home screen. This background sound should be stopped when it goes to other views and should be enabled when user come back to the home screen again. Below code is working fine in IOS7, when I upgrade to IOS8 background sound continuously playing and doesn’t stop when I go to other views. Kindly help me in this issue.
I am using below code for start and stop the player
NSString *pewPewPath = [[NSBundle mainBundle]pathForResource:#"background" ofType:#"mp3"];
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath];
NSData *data1 = [NSData dataWithContentsOfURL:pewPewURL];
audio = [[AVAudioPlayer alloc] initWithData:data1 error:nil];
audio.volume=8;
[audio play];
Call the [audio stop]; and set nil to the audio instance when you are navigating to another view. And write this code before you call the next view controller.

iOS7 sending SMS from inside the app has a misaligned modal view

I'm writing an app where I need to allow the user sending SMS from within the app.
It works fine on iOS6 but not on iOS7.
When I'm trying to send a text message, the modal view appears but there is a strange gap between the "to" field and the list of possible contacts.
After selecting the first contact, the "to" field slides up and disappears and then I see past messages and my new message but with the same gap again.
I'm attaching two images showing the issue:
Here is the code I'm using:
if([MFMessageComposeViewController canSendText]) {
NSArray *recipents = nil;
NSString *message = #"Let's go";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentModalViewController:messageController animated:YES];
}
Please tell me if know you know how to fix this issue.
Thanks!
Additional info:
This bug only happens in iOS 7.x not in in iOS 6.x
Also, if I use the MFMailComposeViewControllerDelegate to send emails, it works just fine (although they are both implemented by MessageUI.h)...
Ok, I figured it out.
The issue happens because I have a custom UINavigationController.
In my AppDelegate, I had the following code:
UIImage *navBarImage = [UIImage imageNamed:#"BarIos7.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
Once I removed it, everything started working fine.

Using UIWebView's shouldStartLoadWithRequest with Storyboard and prepareForSegue

I have a non storyboard app that has a UITableView with a bunch of cells, upon clicking a cell I push a view controller with a UIWebView, the local html file is loaded based on the cell tapped.
If this UIWebView then has other links in it, I use the UIWebView delegate method shouldStartLoadWithRequest along with this code:
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
//When a html link is clicked in uiwebview
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
//Get components of url
NSArray *urlComponents = [urlString componentsSeparatedByString:#"/"];
//Get last component which should be wanted file name
NSString *wantedLink = [urlComponents objectAtIndex:[urlComponents count]-1];
//Get the url without the dot
NSArray *fileComponents = [wantedLink componentsSeparatedByString:#"."];
NSString *wantedFile = [fileComponents objectAtIndex:0];
ALSDetailViewController *superDetail = [[ALSDetailViewController alloc] initWithNibName:#"ALSProtocolDetailViewController" bundle:nil];
self.alsProtocolDetailViewController = superDetail;
//Check for each wanted file name to see if it matches another file
if ([wantedLink isEqualToString:#"VTachPulseStable.html"]) {
//Open different protocol xib with html file name as parameter, and push the view in
self.alsProtocolDetailViewController.title = #"Ventricular Tachycardia With Pulse";
self.alsProtocolDetailViewController.protocolURL = wantedFile;
self.alsProtocolDetailViewController.protocolSubTitle = #"Stable Without Decompensation";
[self.navigationController pushViewController:self.alsProtocolDetailViewController animated:YES];
return NO;
}
}
This code is from my working old non-storyboard app.
Basically its reloading the same view its currently in with a new loadRequest and pushing it on top of the stack, so the user can go back to the last loadRequest.
Now with storyboard I can not figure out how to accomplish this same function with segue's, I need to invoke these actions and push the controller onto the stack.
I tried performSegueWithIdentifier but had no luck.
If I use a NSURL load request for the webview without pushing a new instance of the view controller on the stack, it works.
But I need the user to be able to go back.
Any ideas how I can accomplish this?
You can use UIWebView's goBack method:
goBack
Loads the previous location in the back-forward list.
You could add some buttons to accomplish this, in the nav bar or an extra toolbar. This is certainly better design than pushing a new view controller instance.
BTW, you can push a view controller onto itself via segues by dragging the segue to the very same view controller in storyboard.
I fixed the issue by using:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
And getting the storyboard item by its ID, and then using the old pushViewController.
Achieved the same effect.

UIDocumentInteractionController: "Open In" visible on iPhone but not on iPad - why?

For testing purposes I wrote two apps:
First one plays an MP3 file using UIDocumentInteractionController
Second one does nothing but registers for the file type "public.mp3"
If I deploy the apps to the iPhone Simulator, my MP3 player app shows a button on top "Open in 'MP3Test'". If I deploy to the iPad Simulator however, there is no button and no "Open In" menu either.
This has been tested with iOS5.
Can somebody explain if this is a bug or a feature and what the reason is behind it?
Depends upon where you are presenting it from.
If you are presenting it from somewhere around the middle of the screen or below, just present from the frame of the object that you are presenting from.
if that is on the navigation bar, try this:
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"License" ofType:#"pdf"];
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
controller.delegate = self;
CGRect navRect = self.navigationController.navigationBar.frame;
navRect.size = CGSizeMake(1500.0f, 40.0f);
[controller presentOptionsMenuFromRect:navRect inView:self.view animated:YES];
The iPad has an affinity for popovers (see UIPopover), why it presents UIActionSheets in them. Facing a similar issue that you had, I had my UIDocumentInteractionController present itself from an UIBarButtonItem (resulting in a UIPopover presentation), rather than from the view itself (something that worked just fine on the iPhone):
Save a reference to the action button (I have mine in my navigation bar).
Use PresentOpenInMenu using the action button reference, rather than the View reference, resulting in a UIPopover-presentation.
Please note that the change does not effect the iPhone app - it behaves likes before, i.e. opens the OpenInMenu from the bottom of the screen just as it would, if you'd used the View reference to present it.
On iPad UIDocumentInteractionController appearing like Pop Up Try something like this
-(void)shareClick:(UIButton*)sender {
/*some code*/
CGRect rectFor appearing = [sender.superview convertRect:sender.frame toView:self.view];
[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];
}

How to open web browser with UIWebView

Hey guys,
On my Xcode project, I am trying to open a web browser at the click of one of my buttons, but here's what I'm really trying to do. First of all, I am opening a web browser using this example code:
NSURL *fanPageURL = [NSURL URLWithString:#"fb://profile/210227459693"];
if (![[UIApplication sharedApplication] openURL: fanPageURL]) {
NSURL *webURL = [NSURL URLWithString:#"http://www.facebook.com/pages/Blackout-Labs/210227459693"];
[[UIApplication sharedApplication] openURL: webURL];
}
[super viewDidLoad];
Now this code works properly, but the problem is that it's closing my application and opens the link in the Safari application, which is not what I want. I went the other way around by creating another view (after click the button), then inserted a UIWebView using Interface Builder, but it still didn't work. So I was hoping someone can help me out how to open this link within my app instead of closing my app and opening the link in the Safari app, thanks
Look at SVWebViewController. It's a ready made UIViewController subclass with a UIWebView in it and all you need to do to show it is
SVWebViewController *webViewController = [[SVWebViewController alloc] initWithAddress:#"http://google.com"];
[self.navigationController pushViewController:webViewController animated:YES];
There is also a modal version, see the Usage Section.
You'll need to create a UIViewController subclass that has UIWebView as a subview, and show that when the button in tapped.