iOS enabling AirPrint for uiwebview contents - iphone

I am super new to XCode and App development. I currently am loading up a web based application in uiwebviews on the iPad. When one particular page is loaded, it displays a pdf file. I would like to be able to print this pdf file using AirPrint. I am looking for a simple solution. Currently the app I am working on has 6 files which it uses.
-ViewController.m
-ViewController.h
-MainStoryboard_iPad.storyboard
-MainStoryboard_iPhone.storyboard
-AppDelegate.h
-AppDelegate.m
In the MainStoryboard files, there are many windows (graphical) which are liked to a central navigation system. If it is possible to spend some time to really explain what I need to do, and not 'take a look at this link.' I have programming experience, but never with XCode or any product related to Apple.

I figured out how to do this. Firstly I found a piece of code here, iOS Air print for UIwebview, I had no idea how to implement this at the time, but then I did as follows.
My application was a single view XCode project
In my storyboard I inserted a button (on my navigation bar) and changed its Identifier to 'Action' then, making sure to have the 'tuxedo' editor view open, displaying my ViewController.m file, I clicked and dragged from the button to the ViewController.m file while holding down control. This inserted my IBAction method after asking for my buttons id.
myActionButton
Then I copied in the code specified in response 3 of the question. My ViewController.m looked something link this.
#import "ViewController.h"
#interface ViewController()
#end
#implementation ViewController()
//Some stuff here
#end
#synthesize webView
-(IBAction)myActionButton:(id)sender{
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
}
Also in my ViewController.h file
#import ...
#interface ViewController : ...
{
IBOutlet UIWebView *webView
}
#property (nonatomic,retain) IBOutlet UIWebView *webView
#end
I didn't setup the webviews so I am not 100% sure on how they are created, but there is a good series for beginners on youtube at HackLife87 which shows how to make a single view app. I think XCode Tutorial Video #7 involves setting up views.
Since I am extremely green to XCode and IPad app development, I managed to solve my problem by combining knowledge from watching the aforementioned XCode tutorial videos and then implementing the solution provided on stackoverflow by Hafthor.

Related

iOS 6.1 UIWebview crashes when clicked on play youtube video inside a webpage

I am trying to show a website inside app. The website which i am trying to load has got a youtube video in it. The website loads properly in UIWebView and also lists the youtube video. But when I click on youtube video, the app crashes.
Crash log just says:
setting movie path: http://r19---sn-aig7knl7.c.youtube.com/videoplayback?...............
The website when loaded in Safari works fine, it even plays youtube video full screen.
Please help me in fixing this issue.
11 Feb 2013 - UPDATE
The issue is observed only on iOS Simulator 6.1. On Device everything works fine.
Detailed Info:
I have a custom UIViewController(TestWebViewController) which has an instance of UIWebView and implements UIWebViewDelegate. I have added a UIViewController in Storyboard and added UIWebView inside it, linked this UIViewController to my custom TestWebViewController and linked IBOutlet and delegate for UIWebView.
On Clicking a button, I am programmatically instantiating TestWebViewController using
TestWebViewController *testWebVC = [self.storyboard instantiateViewControllerWithIdentifier:#"testWebVC"];
testWebVC.view.frame = self.view.frame;
[testWebVC loadWebViewWithUrl:TEST_URL];
[self presentViewController:testWebVC animated:YES completion:nil];
As scott said in his comment, I removed my breakpoint for all exceptions and my error went away.
Hope this will help to others.
Modal view on iOS 5.0 and iOS 5.1 is the problem that causes crash on full screen video, AFAIK. They just changed hierarchy of views in that version of iOS (parentViewController and presentingViewController) and that is the aftermath. I asked about it long time ago here and one more same question is here and still no one knows what to do.
First of all, they fixed it in 6.0, I guess, that's good.
For 5.1 we changed design a little and avoided modal view. Do it, if it is possible in your situation.
TestWebViewController *testWebVC = [self.storyboard instantiateViewControllerWithIdentifier:#"testWebVC"];
[testWebVC LoadWebView:#"YOUR URL STRING"];
[self presentViewController:testWebVC animated:YES completion:nil];
AND in TestWebViewController class
-(void)LoadWebView:(NSString *)address {
addressStr = address;
}
- (void)viewDidLoad
{
[super viewDidLoad];
url = [NSURL URLWithString:addressStr];
NSURLRequest *request = [NSURLRequest requestWithURL:url] ;
[myWebView loadRequest:request] ;
}

InAppSettingsKit multi value not showing options

I have just managed to create my settings.bundle and set up a selection of different settings. However when I run my app and view the settings via InAppSettingsKit, the multi value options aren't displayed. I see the title and I can select it, then when it should display the options it just shows n empty cells (except for the tick).
The odd thing is that if I go into the Apple Settings app and check out the multi value settings they all show up as expected. Does anyone have any idea whats going on?
This is the code I'm using in my .h file:
#import <UIKit/UIKit.h>
#import "IASKAppSettingsViewController.h"
#interface myViewController : UIViewController <IASKSettingsDelegate, UITextViewDelegate>
{
IASKAppSettingsViewController *appSettingsViewController;
}
And in the .m file I have the following:
- (IBAction)optionsButtonSelected:(id)sender
{
appSettingsViewController = [[[IASKAppSettingsViewController alloc] initWithNibName:#"IASKAppSettingsView" bundle:nil] autorelease];
appSettingsViewController.delegate = self;
appSettingsViewController.showDoneButton = YES;
UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:appSettingsViewController] autorelease];
[self presentModalViewController:aNavController animated:YES];
}
Below is a screenshot of a portion of my settings bundle (showing on of the problematic multi-value options):
And here is a screenshot showing what is displayed in the in app settings section when I click on Style:
I managed to resolve this issue by resetting the iPhone simulator. It seems it was getting confused between some old and new plist settings for some reason.
sorry it won't allow me to vote up. I also fixed a similar problem by quitting the simulator and running the app again (also try to delete the app?).

UIWebView loading but not displaying website (XCode 4, iOS SDK 4.3)

i'm going to write an app including an UIWebView. So first I wanted to try it out by just simply loading an URL.
Created the UIWebView in Interface Builder
Hooked up to the code
#property(nonatomic,retain) IBOutlet UIWebView *webView;
viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
if(!webView)
{
webView = [[UIWebView alloc]init];
}
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]]; }
also I implemented the didFailLoadWithError and webViewDidFinishLoad delegate methods.
webViewDidFinishLoad is called and indicating that HTML has been loaded.
Problem is: Even though webViewDidFinishLoad is called, the UIWebView doesn't display the website. It's only showing white color. The scroll bars right and at the bottom are shown when the UIWebView is touched and dragged but not content is visible. Nowhere found anything. Seems quite strange..
EDIT
This screenshot shows the connections of the xib:
Connections
If you hooked everything up in Interface Builder correctly, the following lines should not be needed:
if(!webView)
{
webView = [[UIWebView alloc]init];
}
webView.delegate = self;
Try removing them and see what happens. Also, put an NSLog(...) in the webView:didFailLoadWithError: callback and see if it is output.
I got it.. I used synthesize in the following way:
#synthesize webView = _webView;
So it was necessary to call the UIWebView in the following way:
[self.webView loadRequest:...];
New to this naming convention which is why i'm not used to necessity of self
Have you checked the File's Owner connect to the webView you declared?
Besides, webViewDidFinishLoad does not mean the HTML was loaded!
Whatever the content is loaded successful, this method will be called.

iPhone: Why does applicationMusicPlayer quit playing when app enters background?

I made a little test app to try to isolate this issue, but it exhibits the same behavior: the applicationMusicPlayer stops playing immediately when the app enters the background. I don't know what I'm doing wrong, or if it's an Apple bug. It seems so simple that if it were an Apple bug others would have encountered it and posted on it.
I've set the info.plist UIBackgroundModes key to Audio
I've verified that the app is not terminating
I've tested on 4.1 beta 3 with the same results
I've searched the web for similar complaints. People report other MPMediaPlayerController issues/bugs, but more complex e.g. involving interaction with AVAudio.
Any/all suggestions appreciated.
Here's the core of my test app:
MPTest.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
#interface MPTestViewController : UIViewController <MPMediaPickerControllerDelegate> {
MPMusicPlayerController *MPPlayer;
}
#property (nonatomic, retain) MPMusicPlayerController *MPPlayer;
#end
MPTest.m
#import "MPTestViewController.h"
#implementation MPTestViewController
#synthesize MPPlayer;
- (void)viewDidLoad {
[super viewDidLoad];
// get the application music player
self.MPPlayer = [MPMusicPlayerController applicationMusicPlayer];
// break to allow application didFinishLaunching to complete
[self performSelector:#selector(presentMPPicker) withObject:nil afterDelay:0.01];
}
- (void)presentMPPicker {
// present the picker in a modal view controller
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
// delegate called after user picks a media item
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
[self dismissModalViewControllerAnimated:YES];
// tell the player what to play
[MPPlayer setQueueWithItemCollection:mediaItemCollection];
// start playing
[MPPlayer play];
}
#end
MPMusicPlayerController does not support background audio. You will need to use something like AVAudioPlayer or AVPlayer (AVPlayer allows you to use iPod libary items via the AssetURL).
The reason is that MPMusicPlayerController uses the iPod application to play audio, thus your application is not actually playing anything.
Please see this thread on the Apple Developer Forums for more information: https://devforums.apple.com/thread/47905?start=0&tstart=120
Did you set the appropriate audio session type for being a media player? The OS uses session types to make decisions among competing uses for the audio channels.

iPhone - Anyway to get iPhone's Email App Inside Your Own App?

Has anyone every embeded the iPhone's Email program inside your own App?
Let me try and simplify that. Tap Tap Revenge allows you to "Challenge A Friend". When you choose to do so they open the standard iPhone email program (if they mimicked it, it looks damn good), within the application with pre-populated data. All you have to do is select a friend from your contacts and press send. You never leave the Tap Tap Revenge App.
Any ideas how this is done?
You need to include the MessageUI.framework into your project, and inside your header file you need to set the delegate:
#import <MessageUI/MessageUI.h>
#interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
MFMailComposeViewController *email;
}
#property (nonatomic, retain) MFMailComposeViewController *email;
Once you do that, you have a few delegate methods inside your implementation file you need to include (You should check to see the result, but I am trying to keep as little code as needed):
#synthesize email;
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[email dismissModalViewControllerAnimated:YES];
}
Wherever you want to use this, you need to initialize and set it up like this:
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:#"Testing"];
// Optional Attachments
NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:#"albumart.png"]);
[email addAttachmentData:artwork mimeType:#"image/png" fileName:#"albumart.png"];
// Body
[email setMessageBody:#"This is the body"];
// Present it
[self presentModalViewController:email animated:YES];
Further to Garett's great response, should you get the warning:
'MFMailComposeViewController' may not respond to '-setMessageBody:'
add isHTML: so the complete line reads like:
[mail setMessageBody:#"This is the body" isHTML:NO];
There is two answers for that. For applications that should support iPhone OS prior 3.0 the only way to go is to build a custom message composer. Or you may want to have a look at the component built by Joe Hewitt who wrote the Facebook iPhone app.
http://github.com/joehewitt/three20/blob/master/src/Three20/TTMessageController.h
With iPhone SDK 3.0 you are able to use the Mail message composer UI straight out if the box using the MessageUI.framework as explained above.
messagecomposer is the way to go! mails and sms inside the app, run from iOS 3.1. need sdk 4