objective-c

Objective-C Soap

https://github.com/iPolaris/SoapRequest
http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Resp

//Import the frameworks header to your ViewController header file :
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "SBJson.h" 

//Unfortunately, there is no framework to create a SOAP message for us, so we will create the SOAP message as follows (this is the routine) :
- (IBAction)btnConvert:(id)sender {
   
    NSString *soapMessage = [NSString stringWithFormat:@"\n"
         "\n"
         "\n"
         " \n"
         "%@\n"
         "\n"
         "\n"
         "\n" ,textFieldCelcisus.text];
    
    
    NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLConnection *theConnection = 
      [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if( theConnection )
    {
        webData = [NSMutableData data] ;
        NSLog(@"Problem");
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
       
    
}// end of buton convert


//After making our request to the server, we need to catch the server response, for this. By using the connectionDidFinishLoading method, we catch the service response.
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
   
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: 
      [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
}


//Now we got the data in XML form, but we need to parse this XML to get our fahrenheit value. To do that, we need to add NSXMLParser's delegate to our viewController:
@interface SEViewController : UIViewController  

//In connectionDidFinishLoading method, we create an NSXMLParser object and pass the server response to it:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: 
      [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
   
    NSData *myData = [theXML dataUsingEncoding:NSUTF8StringEncoding];
   
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
   
    // Don't forget to set the delegate!
    xmlParser.delegate = self;
   
    // Run the parser
    BOOL parsingResult = [xmlParser parse];
   
}

//Finally, we will implement NSXMLParser's delegate methods to get each element:


-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:
    (NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSString  *currentDescription = [NSString alloc];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    curDescription = string;
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if([elementName isEqual: @"CelsiusToFahrenheitResult"]);
    textFieldResult.text = curDescription;
} 

Objective-C 文件操作

常见的NSFileManger文件方法: (continue reading…)

1 Comment more...

XCode调试技巧之EXC_BAD_ACCESS中BUG解决

XCode调试技巧之EXC_BAD_ACCESS中BUG解决是本文要介绍的内容,在iphone开发的时候EXC_BAD_ACCESS这个bug时不容易找到原因的,在网上找到的3个关于这个问题的方法,希望可以帮到你,我自己试了一下第一中方法,效果还不错 (continue reading…)


Objective-C语法快速参考

大部分有一点其他平台开发基础的初学者看到XCode,第一感想是磨拳擦掌,看到Interface Builder之后,第一感想是跃跃欲试,而看到Objective-C的语法,第一感想就变成就望而却步了。

如果你和我一样,对苹果相关的开发:Mac OS X或是iPhone有兴趣,但是第一时间看到Objective-C就会头疼并伴有发烧症状的话,疗效比较好的快速治疗方法是阅读本文。大概花二十分钟左右,而且绝不无聊的时间,你就会对Objective-C有那么一点点了解,至少读读例子不会那么头疼了。

不过假定你要有那么一点点C++、C#或是Java的基础,至少能看到C++、C#或是Java的源码,能够大致明白说得是什么。

这篇文章不是一篇科技文章,希望你也不要把它当做科技文章来读。文章非常不严谨,但是我相信你能看得懂。 (continue reading…)


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress