Setting up Contact Form in Xcode - iphone

I'm relatively new to Xcode, and am trying to style and create a very basic app before I move onto more complex things - so I'm learning all the time.
So I've got my Contact Form view controller all styled up, and I'd like to figure out how to pull the inputted data through so when the user clicks Submit, it send it all through to the defined email address. I'm aware this requires a bit of php server side which I'm happy with, but it's the basic collating in Xcode that's causing an issue - allocating actions/code etc.
Plenty of tutorials explain how to create a form from scratch, but it's implementing it into an existing project that's proving tricky - I have a view Controller setup already with the required interface.
The screenshot of my view controller is here: http://pixelproofdesign.co.uk/stackoverflow/View%20Controller%20Screenshot.png
You can find the project files here: http://pixelproofdesign.co.uk/stackoverflow/Pixel%20Proof_NEW.zip
Any help would be hugely appreciated - it's driving me round the bend!

Connect each text field of the form to an outlet in the .H file. This will then allow you to get at the text property when the user taps the Contact Us button.
#property (weak, nonatomic) IBOutlet UITextField *contactName;
#property (weak, nonatomic) IBOutlet UITextField *contactEmail;
#property (weak, nonatomic) IBOutlet UITextField *contactPhone;
#property (weak, nonatomic) IBOutlet UITextField *contactDescription;
Add an action to that button and concatenate the text fields into an NSString, e.g.
NSString *message = [NSString stringWithFormat:#"name=%#&email=%#&phone=%#&description=%#",
self.contactName.text,
self.contactEmail.text,
self.contactPhone.text,
self.contactDescription.text];
Then you can send this as a POST and the PHP will get each field as a variable. See also sending form data via HTTP POST

when you are done collecting data build up up a NSDictionary
id dict = #{#"formField1": formField1.stringValue; #"FormField2": formField2.stringValue};
=> the resulting dictionary you form encode so you can put it to html (category to get postData
id data = [dict postData];
=> then transfer it using NSURLConnection
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"www.url.de"]];
[request setHTTPBody:data];
[request setHTTPMethod:#"POST"];
[request setValue:#"multipart/form-data, boundary=--------------BOUNDARY------------------" forHTTPHeaderField:#"Content-type"];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
Disclaimer:
I wrote this inline here and never tested it for typos
This is a very basic way to do it and when it gets more complex, I'd look into using a Framework ...e.g. AFNetwork

Related

Playing Video on UIWebView getting Access Denied

Hello Everyone i am trying to play video based on URL that i am getting through API but i am getting Error like Access Denied.
The reason why i am playing video in UIWebView is because Video is not the Primary feature in my Application its just for Show Tutorial to the User so i have not used MPMoviePlayerController but if required than i can use.
But i want know the exact reason why such Error occurs in UIWebView.
Any guide or help will be appreciated.
Thanks in Advance.
Add below method to your ViewController.m :
//This method should get called when you want to add and load the webview
- (void)loadUIWebView
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
[self.view addSubview:webView];
[webView release]; // No need of this line if ARC is implemented in your project
}
Using Interface Builder-
Add a UIWebView object to your interface.
Set the "hidden" property to checked (in the "Attributes Inspector" window in Interface Builder). You should keep it hidden until you want to display WebView.
Add the following code to your ViewController.h.
#property (nonatomic, retain) IBOutlet UIWebView *webView;
Add the following line below the #synthesize in your ViewController.m
#synthesize webView;
Add [webView release]; in the dealloc method. // No need of this line if ARC is implemented in your project
}
Go back into IB and click on File's Owner, and connect the webView
outlet to the webView you created.
Add the following method.
//This method should get called when you want to add and load the webview
- (void)loadUIWebView
{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
self.webView.hidden = NO;
}
I hope it will help you.

UIWebView accepts normal NSStrings but not a NSString from an object

So I have an object called 'theList', this contains a load of information about a student, one element is a url to an image of their work online. I am using a webview to display that image using the code:
NSString *urlAddress2 = theList.imageofwork;
NSURL *url2 = [NSURL URLWithString:urlAddress2];
NSURLRequest *requestObj2 = [NSURLRequest requestWithURL:url2];
[workWeb loadRequest:requestObj2];
This doesnt work, but when I change 'theList.imageofwork' (which contains 'http://google.com' I should say, while I test this) to '#"http://google.com"' it works absolutely fine.
Though I need this to be able to draw from 'theList' as the view is general and should change depending on the student that you select. So my question is what am I doing wrong or is there some other way that I should be going about displaying images?
Also, within theList.h, imageofwork is declared as:
#property (nonatomic, retain) NSString *imageofwork;
and in theList.m I have:
#synthesize imageofwork;
I should also mention that I am relatively new to xcode and this is my first post here!
Thanks in advance.
You should read the documentation of the UIWebView class more carefully.
Here is what you should need: loadHTMLString:baseURL:

how to put text in Webview?

I have this kind of 4 paragraphs.
like this:
I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition.
I want to use this paragraphs in different views using webview.
I mean I want to show such paragraphs in UIWebview
can anyone please tell me how to do this?
[webView1 loadHTMLString:#"Welcome to StackOverFlow" baseURL:nil];
[myWebView loadHTMLString:#"<p>I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition</p>"]
If you really have to show the Text in an UIWebview implement a class which implements the UIWebView Delegate protocoll, like this:
#interface Web : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
NSString *uRLString;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) NSString *uRLString;
in your .m file you set the delegate and the view in your viewDidLoad like this:
self.view = webView.view;
self.webView.delegate = self;
and implement the openURL like this:
- (void)openURL:(NSString *)urlString
{
[myWebView loadHTMLString: <your static string in html-formate>]
}
But like I said before: You should use an UITextView to stick to Apple guidelines and you can also set preferences of UITextView without IB. In fact you really never HAVE to use the IB.

Any examples/tutorials on using Google GData API - Youtube on iphone?

I need to list a specific users uploaded videos (YouTube) in a UITableView. I've downloaded the GData source and example projects (not iphone specific) but I can't seem to get it to work. Does anybody know of any good (or any at all ;)) tutorials out there?
Best regards,
Magnus
Assuming you have included the GData client libraries to your project, you need to make a call to fetch the user's uploads, and then display them. Here's the simplest way I can think of:
Create an instance variable in your table view controller class that will hold the feed data returned from the YouTube API.
RootViewController.h
#import "GDataYouTube.h"
#import "GDataServiceGoogleYouTube.h"
#interface RootViewController : UITableViewController {
GDataFeedYouTubeVideo *feed;
}
#property (nonatomic, retain) GDataFeedYouTubeVideo *feed;
Inside the implementation file, make a call to the API to fetch all uploaded videos. Inside the callback selector request:finishedWithFeed:error, store the results in whatever format suits, and reload the table view. In the table views cellForRowAtIndexPath method, format the cell as desired:
RootViewController.m
// get the youtube service
GDataServiceGoogleYouTube *service = [self youTubeService];
// feed id for user uploads
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:#"annoyingorange"
userFeedID:uploadsID];
// make API call
[service fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(request:finishedWithFeed:error:)];
Checkout the full source code for RootViewController.

How to save and view a pdf file through an app on iPhone?

I am trying to save a pdf file in SQLite. I think it will be possible by saving the pdf file as blob. And the problem starts here, how to view that file within the iPhone app now?
I know it can be done using this code:-
#interface PDFViewController : UIViewController {
UIWebView *webView;
NSURL *pdfUrl;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) NSURL *pdfUrl;
#end
#implementation PDFViewController
#synthesize webView, pdfUrl;
- (void)viewDidLoad {
[super viewDidLoad];
// Tells the webView to load pdfUrl
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
But what should be the value of the pdfUrl,I am confused...
And if I retrieve it from the DB it will be in a blob format(methinks) so how to convert it into a NSdata object?
Thank You All.
The problem is that WebView does the URL loading, and it won't understand things like non-http requests; yet your application is trying to serve the data. So basically, you're out of luck, unless you can deserialise the blob out of the sqllite database, write it to a file (in /tmp, say) and then open up a file:/// URL from the NSWebView - but I don't believe that the object will let you do that.
You might be able to invoke the [UIWebView loadData:MIMEType:textEncodingName:baseURL:] method, which will allow you to extract the NSData blob from the sqllite database, supply a mime-type of application/pdf, stick in a dummy text encoding (UTF-8) and base URL, and then it might do what you want. But I'd be tempted to try that at least.
the pdfUrl is the web address of the PDF you are tryign to download from the website. (ie http://website.com/mypdf.pdf)
Read the documentation on NSData, it has a method to allow you to create NSData objects based no what you pull out using sqlite.