As per requirement I need to post user profile details like user name, first name, last name and profile picture from IPhone device. How can we send these details including “profile picture” together? Do I need to send these details as a JSON object? So I need to convert the image as byte array. Right?
If you can provide any IPhone code snippet then it would be better.
Also if possible please provide the code for WCF Rest service Part.
Thanks in advance.
To send data to the server in JSON format:
ADD:
JSON.h (Header)
JSON.m (Implementation)
Use
https://github.com/stig/json-framework/download
To convert your profile details, you can refer following sample
NSMutableDictionary *jsonEncode = [NSMutableDictionary dictionary];
[jsonEncode setValue:#"" forKey:#""];
NSString *jsonString = [jsonEncode JSONString];
To send Image to server you need to convert image into Base64 format.
Refer link below:
UIImage to base64 String Encoding
Related
I am developing an iPhone application that is using an API to find recipes from http://www.recipepuppy.com/about/api/.
There are three parameters that must be put into return results. There are i,q, and p, Where i are the ingredients, q in a normal search query and p is the page #. I am able to specifically add these parameters and then load the results into a table view in Xcode.
I also want to implement a search that allows the users to search for recipes based on whatever they feel like and return the results. Could someone point me in the correct direction on how to do this. I know I will have to take what ever the user inputs and place it into a string but how do I implement that string into the parameters of the URL?
To answer your question:
I know I will have to take what ever the user inputs and place it into a string but how do I implement that string into the parameters of the URL?
You can use the stringWithFormat method of NSString. For example:
NSString *ingredients = #"ingredients";
NSString *query = #"soups";
NSString *page = #"1";
NSString *url = [NSString stringWithFormat:#"http://www.recipepuppy.com/api/?i=%#&q=%#&p=%#",ingredients,query,page];
Before using this URL, it's recommended that you URL encode it.
NSString *encodedURL = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Now that you have your URL, just start a connection to the web (NSURLConnection, AFNetworking, the choice is yours), parse the data returned, and load that into an array to display in the table view.
To build a solid app that involves JSON communication over the network, you can use the JSONModel library. It provides you with data models, and takes care of sending and receiving JSON forth and back to your API service.
You can have a look at the GitHub page:
https://github.com/icanzilb/JSONModel/
Or also to this example on how to use the YouTube JSON API with JSONModel:
http://www.touch-code-magazine.com/how-to-make-a-youtube-app-using-mgbox-and-jsonmodel/
On the GitHub page there are more code samples. Good luck :)
(Disclosure: I'm JSONModel's author)
I'd use AFNetworking for all your network requests:
https://github.com/AFNetworking/AFNetworking
To make the request just construct an NSString and send it off
[NSString stringWithFormat:#"http://www.recipepuppy.com/api/?i=%#&q=%#&p=%d", self.ingredients, self.query, self.page]
I have my app setup to all Open-in with various document types. For example, user opens a PDF into my app and then rather than displaying it I have them select what folder they want to put it into and upload it to my server. I am taking the url, converting it to NSData and uploading that to my server (works great).
Then, when they want to view the file at a later time I am pulling the NSData from my server...this is where I am getting stuck. How do I take that NSData object and display the contents to the user from within my app? Thank you.
If the server doesn't require any user/password challenge you can just do
NSURL*url=[NSURL URLWithString:#"your url goes here"];
NSData*data=[NSData dataWithContentsOfURL:url];
Your can also have more control of your download using NSURLRequest and implementing the NSURLConnection class with it delegate methods
If you implement the NSURLRequest with a NSURLConnection you can challenge the user/password
For large content you can do the class method
+ sendAsynchronousRequest:queue:completionHandler:
For creating the pdf document from a NSData you can do:
CFDataRef myPDFData = (CFDataRef)data;
CGDataProviderRef provider= CGDataProviderCreateWithCFData(myPDFData);
CGPDFDocumentRef pdf= CGPDFDocumentCreateWithProvider(provider);
Where data is your received data
You either have to include view support for each type of document you are planning to support or hand over that task to another app which can do it for you using UIDocumentInteractionController.
See Document Interaction Programming Topics for iOS for more info.
Use a UIWebView to display NSData containing PDF
[self.webView loadData:data MIMEType:#"application/pdf" textEncodingName:#"utf-8" baseURL:nil];
Web Views can display different Data.
I'm trying to set up a prefilled email for the user to send through the iphone native Mail application. The body of the email contains a link that the user wants to share.
My problem is that the link is getting cut off by the Mail app but when I print out the string in my app the whole link is there.
Here is a sample link:
http://sample.com/Start.asp?tqnm=xe2nbek92057479&bt=xg&o=100925&c=RB&p=2W7TvRx1
In the mail app the link shows up as:
http://sample.com/Start.asp?tqnm=xe2nbek92057479
I am using the standard code for launching the Mail app:
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(#"Mail String: %#", mailString);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
I've also tried other string encodings but I either get the same result or the body of the email doesn't show up at all.
Any help would be really appreciated. I've been looking for the answer for a while and haven't found anything to even point me in the right direction.
I was able to solve it, I found this function
NSString* encodeToPercentEscapeString(NSString *string) {
return (NSString *)
CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef) string,
NULL,
(CFStringRef) #"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8);
Then I used that to encode the body, which took care of the ampersand case, which Matthias was referring to. Thank you Matthias for pointing me in the right direction.
This is perhaps more a work-around than an answer, but... You might consider using the MessageUI framework to send the mail directly from within your app. You can easily set the body of the mail without any encoding issues and it also a little bit nicer for the user (i.e. does not switch away from your application).
There are plenty of tutorials/code snippets on the web about how to do this. (I wrote this one a while ago Sending Mail from your App). Hope this helps!
I've the following problem:
I'm parsing an XML File from Flickr API http://api.flickr.com/services/feeds/photos_public.gne?tags= with a specific tag, provided by the user before.
Then I get a XML file where in each
<entry> item a line exists like
<link rel="enclosure" type="image/jpeg" href="IMAGEURL">
Is there an easy way to parse this line of code with NSXMLParser? Or should I use another way to get the IMAGEURL?
You should be able to use the delegate method parser:didStartElement:namespaceURI:qualifiedName:attributes: to get that info. The attributes are available in the attributesDict. So you can get the IMAGEURL using,
NSString * imageURLString = [attributesDict objectForKey:#"href"];
when elementName is "link".
I have tried this as well and it doesn't work anymore because the html is not well formed xml. This is the error I got: NSXMLParserErrorDomain Code=111
Now using the Flickr API and it works like a charm.
You have to create an API key: https://www.flickr.com/services/apps/create/
I have an application which binds a map with user's location, 2 pictures and some text in the xml file and send it to the other user through email.
Now the question is that if the other user who is receiving it, how i should make this xml file parsed in my application so that the receiver can have a sensible look of the data like the map with two tabs (pictures and comments).
The basic question is how i can read the sent xml file at receiver's end.
Thanks,
At the sender's end, create an NSDictionary containing the location, the data of the two UIImages and the NSString. Then, save it as a plist, and send it via email. Then, at the receiver's end, create an NSDictionary with the contents of the file (NSDictionary *dataDict = [[NSDictionary alloc] initWithContentsOfFile:YOUR_FILE];), and then get the objects using the relevant keys that you set for them when you added them to the dictionary.
Hope this helps,
jrtc27