2011-10-13 2 views
0

내 응용 프로그램을 통해 yFrog를 사용하여 트위터에 이미지 및 비디오를 게시하려고하지만 요청을 할 때 아무 것도 일어나지 않는 것 같습니다 ... 누군가 내가 뭘 잘못하고 있는지 또는 나를 가리켜 주실 수 있습니까? 바른 길? 당신은 내가 당신이 대리인에게 자기 설정을 참조하지만 콜백이 표시되지 않는 대리자 (위 적어도 코드에서) 메소드를 다시 호출 구현하지 않을yFrog에 게시 objc

-(IBAction)yFrogToTwitter 
{ 

// create the URL 

//used to render bigger images videos 
//NSURL *postURL = [NSURL URLWithString:@"http://render.imageshack.us/renderapi/start"]; 
//below is used to directly upload to twitter 
NSURL *postURL = [NSURL URLWithString:@"http://yfrog.com/api/uploadAndPost"]; 


// create the connection 
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:postURL 

cachePolicy:NSURLRequestUseProtocolCachePolicy 
                 timeoutInterval:30.0]; 

// change type to POST (default is GET) 
[postRequest setHTTPMethod:@"POST"]; 



// create data 
NSMutableData *postBody = [NSMutableData data]; 

//NSString *media = PickedImage.image; 
NSString *username = twitterEngine.username; 
NSString *password = twitterEngine.password; 
NSString *message = TweetBody.text; 
NSString *source = @"ThemeCatcher"; 
NSString *api_key= kYFrogKey; 

// just some random text that will never occur in the body 
NSString *stringBoundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo"; 
// header value 
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data; 
boundary=%@",stringBoundary]; 
// set header 
[postRequest addValue:headerBoundary forHTTPHeaderField:@"Content-Type"]; 

// username part 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 
name=\"username\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[username dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 

// password part 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 
name=\"password\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[password dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 


// api_key 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 
name=\"key\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[api_key dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 


// message part 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 
name=\"message\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[message dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 


// source part 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 
name=\"source\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[source dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];  


// media part 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"Content-Disposition: form-data; name=\"media\"; 
filename=\"fish.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"Content-Type: image/jpeg\r\n" 
dataUsingEncoding:NSUTF8StringEncoding]]; 
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" 
dataUsingEncoding:NSUTF8StringEncoding]]; 


NSData *imageData = UIImagePNGRepresentation(PickedImage.image); 


// add Image to body 
[postBody appendData:imageData]; 
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 

// final boundary 
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] 
dataUsingEncoding:NSUTF8StringEncoding]]; 


// add body to post 
[postRequest setHTTPBody:postBody]; 

// pointers to some necessary objects 
//NSURLResponse* response; 
//NSError* error; 

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:postRequest 
delegate:self]; 

if(theConnection) 
{ 
    webData = [[NSMutableData data] retain]; 
} 
else 
{ 
    NSLog(@"theConnection is NULL"); 
} 


} 
+1

답변이 잘못되었거나 부분적으로 정확하지 않은 경우 질문에 대답하는 사용자에게 의견을 보내어 답변을 개선 할 수 있도록하십시오. 감사. –

+0

감사합니다. 나는 Stackoverflow를 사랑하고 내가 이것을 원한다면 누군가에게 불쾌감을주지 않기를 바랍니다. 나는 옳다고 생각했던 것을하고 있었지만 완전히 얻은 것이 두 가지 모두 였고 미래의 모든 질문에 대해 이것을 명심할 것입니다. – FreeAppl3

+0

물론 도움이되지 않았습니다. Thx – bryanmac

답변

1

감사합니다. 또한 당신은 당신이 구현해야하는 대리자 콜백 메소드를 오류 콜백 여기

을 것 확인하고 있는지 확인하십시오 당신은 문제가있는 경우

http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate

didFailWithError가 큰 하나입니다. 모든 NSError 데이터를 읽고 최소로 기록하십시오. 예를 들어

:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [responseData appendData:data]; 
} 

- (void) connectionDidFinishLoading:(NSURLConnection *)connection { 
    [connection release]; 

    NSString* responseString = [[NSString alloc] initWithData:responseData  encoding:NSUTF8StringEncoding]; 
    NSLog(@"result: %@", responseString); 

    [responseString release]; 
} 

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
     NSLog(@"error - read error object for details"); 
} 
+0

당신은 항상 나를 도울 방법을 알고있는 것 같습니다! 정말 고맙습니다!!! 그것은 나에게 요청을 지금 준다 나는 내가 그것을 잡아야하고, url를 몸에 넣고, 트위터 나 자신에게 지어 주어야한다라고 생각한다. 고마워요. 나는 머리카락을 잡아 당겨서 그걸 알아 내려고했습니다. – FreeAppl3

+0

나는 고쳐졌다. 편집 된 코드를 보면 yfrog에 사용 된 여러 xml 콜 아웃이 표시됩니다. 누군가가이 대답을 찾고 비틀 거리면 게시 할 것이라고 생각했습니다. – FreeAppl3

0

내 XmlParser가 귀하의 위임에

// 
// yFrogParser.h 
// PreviewMaker 
// 
// Created by Anthony Cornell on 4/12/12. 
// Copyright (c) 2012 iDevice Designs. All rights reserved. 
// 

#import <Foundation/Foundation.h> 
#import "yFrogObject.h" 

@interface yFrogParser : NSObject<NSXMLParserDelegate>{ 

NSMutableData *recivedData; 
NSMutableArray *imageInfo; 
NSMutableString *currentNodeContent; 
NSXMLParser  *parser; 

yFrogObject *imageObjects; 
NSMutableArray *imageArray; 

} 

@property (readonly, retain) NSMutableArray *imageInfo; 
@property (nonatomic, retain) NSMutableArray *imageArray; 
@property (nonatomic, retain) NSMutableData *recivedData; 

-(id) loadXMLByData:(NSMutableData *)data; 

@end 



// 
// yFrogParser.m 
// PreviewMaker 
// 
// Created by Anthony Cornell on 4/12/12. 
// Copyright (c) 2012 iDevice Designs. All rights reserved. 
// 

#import "yFrogParser.h" 

@implementation yFrogParser 

@synthesize imageInfo,imageArray,recivedData; 

-(id) loadXMLByData:(NSMutableData *)data{ 


imageArray   = [[NSMutableArray alloc] init]; 
recivedData = [[NSMutableData alloc]initWithData:data]; 
parser   = [[NSXMLParser alloc] initWithData:recivedData]; 
parser.delegate = self; 
[parser parse]; 

return self;  

} 
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname 
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
attributes:(NSDictionary *)attributeDict 
{ 


if ([elementname isEqualToString:@"links"]) 
{ 
    imageObjects = [yFrogObject alloc]; 

} 
} 

- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName  
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{ 

if ([elementName isEqualToString:@"image_link"]) { 

    imageObjects.responceURL = currentNodeContent; 
} 

if ([elementName isEqualToString:@"image_bb"]) { 

    imageObjects.forumUrl = currentNodeContent; 
    // NSLog(@"image forum url %@",currentNodeContent); 
}  


if ([elementName isEqualToString:@"links"]) 
{ 
    [imageArray addObject:imageObjects]; 
    [imageObjects release]; 
    imageObjects = nil; 
    [currentNodeContent release]; 
    currentNodeContent = nil; 

} 
} 



- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
currentNodeContent = (NSMutableString *) [string  
              stringByTrimmingCharactersInSet:[NSCharacterSet  
whitespaceAndNewlineCharacterSet]]; 
} 


@end 

아래는 공유의 무드 이러한 성격

-(void) connectionDidFinishLoading:(NSURLConnection *)connection { 
[connection release]; 


parser = [[yFrogParser alloc]init]; 
[parser loadXMLByData:webData]; 

yFrogObject *object = [[parser imageArray]objectAtIndex:0]; 



NSString* responseString = [[NSString alloc] initWithData:webData 
encoding:NSUTF8StringEncoding]; 

//NSLog(@"Parser result: %@", [object responceURL]); 
//NSLog(@"yFrog responce results: %@", responseString); 

[responseString release]; 

} 

의 무언가를! 희망이 있습니다