iPhone Sleep 모드 들어가지 않기

게임이나 뭐 기타등등 작업없이 있어야 하는경우

iPhone이 슬립모드로 들어가지 않게 하는 방법이다..

[UIApplication sharedApplication].idleTimerDisabled = YES;


참~ 쉽죠~잉~

Posted by 마르스

2010/01/18 15:27 2010/01/18 15:27
, ,
Response
No Trackback , No Comment
RSS :
http://lasel.kr/blog/rss/response/25

NSThread 백그라운드 쓰레드 돌리기

프로그래밍을 하다 보면 느끼겠지만 쓰레드는 필수이다.

iPhone에서 백그라운드쓰레드를 돌려보자..

Objective-c 에서는 NSThread 라는 클래스가 있다.

일단 쓰레드 처리할 함수를 만든다.

-(void) myTestThread:(id)anObject {

     NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
     //이곳에 처리할 코드를 넣는다.
    
    [autoreleasepool release];
    [NSThread exit];

}


그리고 쓰레드를 호출한다.

[NSThread detachNewThreadSelector:@selector(myTestThread:) toTarget:self withObject:nil];

간단~

Posted by 마르스

2009/12/24 00:09 2009/12/24 00:09
, , ,
Response
No Trackback , No Comment
RSS :
http://lasel.kr/blog/rss/response/17

UI객체의 TAG 활용..

프로그램을 개발하다 보면 디자인 형태에서가 아닌 런타임 상태에서 객체를 생성해야 하는 경우가 생긴다.

즉 몇개의 객체를 생성해야할지가 실행중 결정될때 이다..

예를들어 버튼을 200개를 생성해야 하거나 또는 등록된 사람수 를 가져와서 사람 수 만큼 버튼을 생성해야할 때 등..

윈도우라면 뭐 다양한 방법이 있을것이다. findwindow 등...

iPhone 에서는 tag 라는 꼬리표 같은 변수가 있다..
- (void)viewDidLoad {
    [super viewDidLoad];

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectZero];
    label1.tag = 100;
    [self.view addSubview:label1];
}

이렇게 뷰로드 부분에 객체를 생성하고.. 다른곳에서 tag 값을 가지고 찾아서 쓸 수 있다.
- (void) applyUser {
   UILabel *label1  = (UILabel *) [self.view viewWithTag:100];
   label1.text = "MARS";
}

저렇게 찾아서 쓸 수 있다.

예전에 tableview를 커스터마이징  해야 하는 일이 있었는데..

TableViewCell 을 이용했더니 속도가 느린것이였다.

그래서 저렇게 셀의 view에다가 직접 올려서 했더니 빠른 퍼포먼스를 얻을 수 있었다.

Posted by 마르스

2009/12/22 21:06 2009/12/22 21:06
, , ,
Response
No Trackback , No Comment
RSS :
http://lasel.kr/blog/rss/response/15

iPhone 스크린샷 찍기



UIGraphicsBeginImageContext(self.bounds.size);

[self.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();


Posted by 마르스

2009/11/29 22:11 2009/11/29 22:11
, ,
Response
No Trackback , No Comment
RSS :
http://lasel.kr/blog/rss/response/11

xcode iphone base64 encode/decode

첨부파일을 다운로드 받고 import 후 아래와 같이 사용


 NSString *sourceString = @"username:password";  
 NSLog(@"Original string: %@", sourceString);  
 NSData *sourceData = [sourceString dataUsingEncoding:NSUTF8StringEncoding];  
 
 NSString *base64EncodedString = [sourceData base64Encoding];  
 NSLog([NSString stringWithFormat:@"Encoded form: %@", base64EncodedString]);  
 
 NSData *decodedData = [NSData dataWithBase64EncodedString:base64EncodedString];  
 NSString *decodedString = [[[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding] autorelease];  
 NSLog([NSString stringWithFormat:@"Decoded again: %@",decodedString]);

Posted by 마르스

2009/11/13 19:01 2009/11/13 19:01
, ,
Response
No Trackback , 2 Comments
RSS :
http://lasel.kr/blog/rss/response/7

Objective-C Http request response


	NSURL *url = [NSURL URLWithString:@"https://www.google.com/accounts/ClientLogin"];
	
	NSMutableURLRequest *loginRequest = [NSMutableURLRequest requestWithURL:url];
	
	[loginRequest setHTTPMethod:@"POST"];
		
	[loginRequest addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
	
	[loginRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
	
	NSString *requestBody = [[NSString alloc]
							 
							 initWithFormat:@"Email=%@&Passwd=%@&service=finance&source=%@",
							 
							 @"mars", @"1234", [NSString stringWithFormat:@"%@%d", @"ashlux-igFinance-1.0"]];
	
	[loginRequest setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding]];	
	
	NSHTTPURLResponse *response = NULL;
	
	NSData *responseData = [NSURLConnection sendSynchronousRequest:loginRequest returningResponse:&response error:nil];
	
	NSString *responseDataString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
	
	NSLog(@"Response from Google: %@", responseDataString);

Posted by 마르스

2009/11/12 23:41 2009/11/12 23:41
,
Response
No Trackback , a comment
RSS :
http://lasel.kr/blog/rss/response/6


블로그 이미지

냉정함을 잃지말자...!!

- 마르스