qik.com, ustream.com이 (가) 아이폰 SDK 3.0을 통해 백그라운드에서 파일을 업로드하는 방법을 알고 싶습니다. Pls 알려주세요. 감사 !아이폰에서 배경 파일 업로드를 어떻게 할 수 있습니까?
답변
에게 heres는 당신을위한 스레드를 시작 당신은 또한있는 NSURLConnection에서 asynchronousRequest을 사용할 수 있습니다 말했다 NSThread 클래스를 heres 링크 http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html ... 조사, 파일 업로드를위한 새로운 스레드를 시작할 수 있습니다 이런 식으로 할 수 있습니다. (기본적으로 내 프로젝트 중 하나에서 붙여 넣기입니다.) & 붙여 넣기. 신용이 개발 포럼에 일부 게시물에 간다, 그러나 더 이상부터 내가 누구인지 모르는 : 당신은 할 수 없습니다, 응용 프로그램이 실행되지 않은 상태에서
- (IBAction)startUpload:(id)sender {
NSString *filename = [NSString stringWithFormat:@"iphone-%d.png", [NSDate timeIntervalSinceReferenceDate]];
NSString *boundary = @"----BOUNDARY_IS_I";
NSURL *url = [NSURL URLWithString:@"http://yourgreatwebsite.com/upload"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[req setValue:contentType forHTTPHeaderField:@"Content-type"];
NSData *imageData = UIImagePNGRepresentation([imageView image]);
// adding the body
NSMutableData *postBody = [NSMutableData data];
// first parameter an image
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"filename\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:imageData];
// second parameter information
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//[postBody appendData:[@"Content-Disposition: form-data; name=\"some_other_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//[postBody appendData:[@"some_other_value" dataUsingEncoding:NSUTF8StringEncoding]];
//[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r \n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPBody:postBody];
//start the spinner and deactivate the buttons...
[self setButtonsEnabled:NO];
[[NSURLConnection alloc] initWithRequest:req delegate:self];
}
#pragma mark urlconnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// this method is called when the server has determined that it
// has enough information to create the NSURLResponse
// it can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.
// receivedData is declared as a method instance elsewhere
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
// release the connection, and the data object
[connection release];
// inform the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Error" message:[NSString stringWithFormat:@"The upload failed with this error: %@", [error localizedDescription]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
#ifdef DEBUG
NSLog(@"upload succeeded!");
#endif
// release the connection, and the data object
[connection release];
NSString *response = [NSString stringWithCString:[receivedData bytes] length:[receivedData length]];
#ifdef DEBUG
NSLog(response);
#endif
}
당신이 배경 업로드로 다스 려하는 경우 (OS 아무튼 그것을 허용하지 않음). 앱이 실행되는 동안 배경 화면이라면 여기에 게시 된 링크와 샘플 코드는 정상적으로 작동합니다.
"백그라운드에서"의미하는 것이 명확하지 않지만 비동기 적으로 업로드하려는 경우에는 NSURLConnection, NSURLRequest를 사용하거나 ASIHTTPRequest이라는 훌륭한 라이브러리를 사용할 수 있습니다. 그것은 잘 작동하고 다운로드 및 업로드 진행을 보여주는 간단한 방법을 제공합니다.
+1 멋진 프레임 워크처럼 보입니다! –
this post (매우 잘 검토 된) 응답을 참조하십시오.
앱이 실행되고 있지 않을 때 백그라운드에서 파일을 업로드 할 수는 없지만 앱이 실행 중일 때는 완전히 수행 할 수 있습니다. 이런 식으로 전경 스레드에 영향을 미치지 않고 진행 상황 등을 표시 할 가능성을 높일 수 있습니다.
- 1. Zend_Service_Rest가 파일 업로드를 수행 할 수 있습니까?
- 2. 숨겨진 iframe을 사용하는 파일 업로드를 취소 할 수 있습니까?
- 3. HTTP를 통해 IIS7로 파일 업로드를 가로 채고 유효성 검사 기준에 따라 업로드를 거부 할 수 있습니까?
- 4. 파일 업로드를 사용하는 Ajax
- 5. 어떻게 아이폰에서 webview transpernt 수 있습니까?
- 6. 어떻게 아이폰에서 사용자의 위치를 얻을 수 있습니까?
- 7. 파일 업로드를 허용 할 수있는 PHP 페이지를 어떻게 만듭니 까?
- 8. 아이폰에서 utf8 NSstring을 어떻게 디코딩 할 수 있습니까?
- 9. 아이폰에서 어떻게 메뉴를 만들 수 있습니까?
- 10. [jquery] 파일 업로드를 어떻게 동적으로 추가합니까?
- 11. 아이폰에서 앱 실행중인 배경을 어떻게 죽일 수 있습니까?
- 12. IPhone : 배경 업로드를 위해 dispatch_async를 사용하여 파일 업로드
- 13. 아이폰에서 더미 객체를 시뮬레이션 할 수 있습니까?
- 14. 파일 업로드를 테스트하는 JWebUnit
- 15. 아이폰에서 배경 이미지를 확장하는 방법?
- 16. GWT로 파일 업로드를 처리하려면 어떻게해야합니까?
- 17. 브라우저를 종료 한 후 파일 업로드를 계속할 수 있습니까?
- 18. 스크롤하는 내용으로 스크롤 할 배경 이미지를 어떻게 설정할 수 있습니까?
- 19. 모든 파일 업로드를 암호화하는 GnuPG
- 20. 파일 업로드를 디버깅하는 방법은 무엇입니까?
- 21. .sass 파일 업로드를 중단 하시겠습니까?
- 22. 아이폰에서 NSFileManager를 사용할 수 있습니까?
- 23. 이 배경 효과는 어떻게 만들 수 있습니까?
- 24. 요청을 조롱. 빈 파일 업로드를 테스트하는 파일
- 25. 스트리밍을 사용하여 웹 파일을 소스로 사용하여 웹 API에 파일 업로드를 수행 할 수 있습니까?
- 26. 아이폰에서 파일 해독하기
- 27. "위치"배경 스레드에서 무엇을 할 수 있습니까?
- 28. 한 서버에 게시 된 파일 업로드를 다른 서버로 직접 바운스 할 수 있습니까?
- 29. 웹 서비스에서 파일 업로드를 처리하는 방법
- 30. 아이폰에서 다른 앱을 시작할 수 있습니까?
안녕하세요 qik.com 또는 ustream.com처럼 iphone에서 서버로 콘텐츠를 업로드 할 때 데몬. 따라서 앱 종료시에도 작업이 백그라운드 데몬으로 계속 남아 있습니다. 동일한 방법으로 데몬 프로세스를 구현할 수있는 방법이 있습니까? 감사 !!! – dvch
이것에 대해 확실합니까? – Daniel