지도 위에 아이콘을 UIView를 사용하여 뿌리는데 iPhone4에서 제대로 이미지가 적용이 되지 않았다

해당 문제에 대해 기존 코드를 다 분해해본 결과 원인은 위 함수가 문제 였다.

retina디스플레이에 맞는 해상도 스케일이 위 함수에서는 제대로 적용이 안되었던 것 같다.

해당 문제에 대해 서칭해본 결과 아래 블로그를 찾았다.

http://www.waterworld.com.hk/en/blog/uigraphicsbeginimagecontext-and-retina-display

UIGraphicsBeginImageContext 를 retina디스플레이에 제대로 적용하기 위해서는 UIGraphicsBeginImageContextWithOptions 를

사용해야 했고 단말 기기의 버전에 따라 호출 함수를 결정해줘야하는 번거로움이 생겼다.

하지만 문제를 해결했으니 다행이다.

위 블로그의 업데이트 된 내용을 보니 ipad쪽에서 UIScreen의 scale을 불러오는 부분에 문제가 있는것 같아 코드를 수정하였다.

void RetinaAwareUIGraphicsBeginImageContext(CGSize size) {
static CGFloat scale = -1.0;
if (scale<0.0) {
UIScreen *screen = [UIScreen mainScreen];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {
if( [screen respondsToSelector:@selector(scale)] ){
scale = [screen scale] ;
}else {
scale = 1.0;
}
}
else {
scale = 0.0; // mean use old api
}
}
if (scale>0.0) {
UIGraphicsBeginImageContextWithOptions(size, NO, scale);
}
else {
UIGraphicsBeginImageContext(size);
}
}

이번에 아이콘 변경작업을 하면서 많은 일이 생긴것 같다. 이번 기회에 제대로 당한듯 ㅠㅠ


보통 아이콘 설정에는 

Icon file
CFBundleIconFiles

두 항목에서 설정할 수 있다.
이번에 아이콘을 변경하면서 위 두항목을 모두 변경하고 난 뒤 앱스토어에 등록을 하였는데 오류가 발생하여 거절당했다
원인은 CFBundleIconFile 부분에 디렉토리 명을 삽입하였는데 그 부분이 문제였다.

아이콘 파일이 많아 resource 디렉토리 밑에 디렉토리를 하나 생성하여 넣은 후 프로젝트에 추가를 시켜 놓았는데 상대 경로로 입력해야 되는 걸로 알고 디렉토리명을 넣었다가 오류가 난것이였다(하지만 시뮬레이터와 디바이스에 테스트 할땐 제대로 돌아간다!!!! -_-). 즉 소스내 이미지 파일을 사용하듯 설정 부분에서도 아이콘 명만 기입해야 했었다! -_-;;; 생각해보니 아카이빙할 때 디렉토리라는 개념이 없이 하나의 패키지로 담는데 경로를 지정하니 당연히 제대로 읽지 못하는 것이었다.

거절 이후 원인을 찾아 해결 한 후 다시 앱스토어에 등록을 하였는데.... 이런! 아이폰4에서 아이콘이 흐릿하게 나오는 것이 아닌가? 아마도 아이폰3 아이콘이 나오는것 같았다(@2x.png 이미지가 제대로 안먹힌 것 같았다)

수소문 끝에 원인을 찾아보니 xml 설정에 문제가 있었다.


저렇게 설정해도 빌드에는 문제가 안되지만 아마 CFBundleIconfile항목아래에 있는 Icon.png 파일을 읽어들여 뿌리는것 같다. 즉 아이폰 4에서도 아이폰 3아이콘이 나오는 이유는 저부분이였다. 즉 아래의 기종에 따른 아이콘 설정들이 적용이 안되는 것이다. -_-;

원인이 되는 부분은 key 항목의 Icon files 부분이였다. 저렇게 해도 빌드에는 문제가 안되지만 아래 설정을 깔끔하게 무시하는것 같다.

수정은 Icon files를 CFBundleIconFiles로 변경하니 제대로 아이콘이 적용되었다.


아 정말... 힘들다 ㅠㅠ 단순한 아이콘 설정에도 이렇게 예외상황이 많을 줄이야 ㅠㅠ



1. QuartzCore 프레임워크를 추가한다

2. 헤더에 QuartzCore를 추가한다.

2. 해당 view, button 객체에 아래와 같이 작업을 해준다

둥근 모서리 : [button.layer setCornerRadius:0.0f]
테두리 두께 : [button.layer setBorderWidth:2.0f]
테두리 색 :
UIColor * boarderColor = [[UIColor alloc] initWithRed:xxxx green:xxx blue:xxx alpha:xxx];
[button.layer setBorderColor:[boardercolor CGColor]]

'iOS' 카테고리의 다른 글

아이폰 아이콘 설정 주의사항  (0) 2011.03.11
아이폰 개발 유용팁  (0) 2011.03.11
userInteractionEnabled 영향  (0) 2011.03.04
NSMutableArray 생성 방법  (0) 2011.03.02
Objective C Delegate 활용  (0) 2011.02.24

아이폰의 테이블뷰의 속성 중 userInteractionEnabled을 NO로 지정하게 되면 UITableViewDelegate 가 동작하지 않는다

이 경우 아래의 메소드를 구현하여 임의의 지역에 이벤트를 발생하도록 할 수 있다

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event



- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 UITouch *touch  = [touches anyObject];
 CGPoint touchPoint   = [touch locationInView:i_tableView];

if ( touchPoint.y > y && touchPoint.y < y+cell_height )
 { 
             특정동작 
 }

-------------  생략 -----------------------------

}




NSMutableArray *wordArray = [NSMutableArray array];

-> 컨베니언스 컨스트럭쳐이므로 autorelease상태인 배열을 반환한다. 해당 인스턴스를 반환할때 따로 autoreelase를 표시 하지 말아야 하며 반환 받은 객체에서는 retain - release를 맞춰주어 오너쉽을 유지해야한다


NSMutableArray *wordArray = [[NSMutableArray alloc]init];

-> 기본 인스턴스 생성 방식이므르로 인스턴스를 반환할때 autorelease를 표시하여 오너쉽 포기를 명시해야 한다. 반환 받은 객체에서는 마찬가지로 retain- release를 맞춰주어 오너쉽을 유지해야한다.
상태

1. TownListViewController에서 이벤트 발생시 RootViewControllerSearch 객체의 특정 메소드 실행
-> 특정 데이터 값 교환

해결

1. ViewPageEventDelegate 프로토콜을 생성하여 TownListViewController에 등록하여 해당 프로토콜을 실행하도록 설정



2. Objective C에서는 프로토콜을 클래스 맴버로 설정할 때 일반 객체와 표현 방법이 다름

일반객체

객체명 * 변수명
-> TestObj * testObject;

프로토콜
id<프로토콜명> 변수명
-> id<TestObj> testObject;

3. 델리게이트 프로토콜을 한 객체에 많이 정의 된 경우 클래스 멤버로 나눠 실행 가능할 것 같음


'iOS' 카테고리의 다른 글

userInteractionEnabled 영향  (0) 2011.03.04
NSMutableArray 생성 방법  (0) 2011.03.02
CFURLCreateStringByAddingPercentEscapes 메모리 관리  (0) 2011.02.17
오퍼레이션 큐에서 메모리릭 상황  (0) 2011.02.17
메모리릭 현상(1)  (0) 2011.01.31

 위 함수는 NSString처럼 프레임워크에서 자동으로 메모리 관리해주는 문자열을 반환하지 않는다.
alloc-init과 같이 할당 받은 후 release과정을 통해 메모리 과정에 신경써주어야함

NSString * tempComment  = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)comment, NULL, CFSTR("?&#%<+"), kCFStringEncodingUTF8);

......

[tempComment release];


'iOS' 카테고리의 다른 글

NSMutableArray 생성 방법  (0) 2011.03.02
Objective C Delegate 활용  (0) 2011.02.24
오퍼레이션 큐에서 메모리릭 상황  (0) 2011.02.17
메모리릭 현상(1)  (0) 2011.01.31
Custom UINavigationController  (0) 2011.01.24

상황

1. NSOperationQueue를 상속받아 커스텀 OperationQueue객체를 만듬
2. NSOperation을 상속받은 커스텀 객체를 위 큐에 추가시킴
3. Queue를 진행하면서 Operation을 수행함 -> 완료 될때 마다 Dealloc이 실행됨
4. 모든 Operation을 완료함
5. 완료 후 커스텀 OperationQueue에 Cancel 메세지를 보냄

원인

1. 오퍼레이션 큐의 모든 오퍼레이션이 실행된 후 dealloc상태에서 Cancel 메세지를 발생시키면 임의의 오퍼레이션에서 Cancel메세지가 발생되어 메모리 릭이 발생된다. 왜 완료된 오퍼레이션에서 Cancel이 작동되는지 정확한 원인은 파악이 안됨
2. 여기서 사용되는 큐는 커스텀 프로그래스 바 작업을 위해 일반 스레드 -> 메인스레드로 변경하는 부분이 들어가 있 작업하는 것이 이유가 되는 것 같음

// 메인스레드로 바꾸는 예
if([NSThread isMainThread] == NO)
{
[self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
return;
}

'iOS' 카테고리의 다른 글

Objective C Delegate 활용  (0) 2011.02.24
CFURLCreateStringByAddingPercentEscapes 메모리 관리  (0) 2011.02.17
메모리릭 현상(1)  (0) 2011.01.31
Custom UINavigationController  (0) 2011.01.24
iPhone TestCase 생성  (0) 2011.01.18

메소드내 선언된 변수를 반복문에서 다시 선언 할 경우 메모리릭이 발생할 수 있음

NSMutableArray *array = [NSMutableArray array];
...
...
for(int i = 0; i < spotInfo.i_commentArray.count; i++)
{
NSMutableArray *array = [NSMutableArray array];  // <-- 메모리릭 발생가능
...
...
}

'iOS' 카테고리의 다른 글

CFURLCreateStringByAddingPercentEscapes 메모리 관리  (0) 2011.02.17
오퍼레이션 큐에서 메모리릭 상황  (0) 2011.02.17
Custom UINavigationController  (0) 2011.01.24
iPhone TestCase 생성  (0) 2011.01.18
NSOperation  (0) 2011.01.11


아이폰 기본 UINavigationController 사용 외 Custom하는 방법

1. UINavigationController를 상속받은 객체를 생성한다.
-> 초기화시 navigationBarHidden 속성을 YES로 변경한다

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

@interface NavController : UINavigationController <UINavigationControllerDelegate> {
NavViewController * i_rootController;
}
@end
-------------------------------------------------------------------------------------------------------------

#import "NavController.h"
@implementation NavController
- (id)init
{
    if(self = [super init])
 {
  self.navigationBarHidden = YES;
 }
    return self;
}
@end


2. 네비게이션을 최초로 실행하는 Controller에서 삽입할 ViewController를 생성한 뒤 위 상속받은 네비게이션컨트롤러에 initWithRootViewController 메소드를 통해 초기화 후 addSubview를 통해 상위 View에 할당한다

UIViewController * navView;
navView = [[NavViewController alloc] init];
i_navControllerArray = [[NavController alloc] initWithRootViewController:navView];
[self.window addSubview:i_navControllerArray.view]; 
[navView release];

3. 생성된 View의 초기화 단계에서는 네이게이션바를 대체할 수있는 커스텀 UI를 생성한다

if(self = [super init])
{
 i_tnb  = [TNB getTnbWithTitle:@"테스트맵" LeftTitle:@"이전" AndRightTitle:@"지도"];
 [i_tnb addTarget:self actionForRightButton:@selector(onShowMapButton:)];
 
 [self.view addSubview:i_tnb];
}

4. 해당 UI에서 네비게이션 버튼 클릭시 발생되는 이벤트시 페이지 이동을 위해서 pushViewController 메소드를 사용하여 신규 View Controller 페이지를 네비게이트 시킨다.
- (void) onShowMapButton:(id)sender
{
 NSLog(@"MapButton");
 
 MapViewController * mapViewController = [[MapViewController alloc]init] ;
 
 [self.navigationController pushViewController:mapViewController animated:YES];
 
 [mapViewController release];
 
}

5. 네이게이트 된 후 이전 페이지로 돌아갈 경우 popViewControllerAnimated 메소드를 사용하여 이전 페이지로 돌아간다
@implementation MapViewController
-(id) init {
 
 if(self = [super init])
 {
  i_tnb  = [TNB getTnbWithTitle:@"맵" LeftTitle:@"이전" AndRightTitle:@"현재위치"];
  [i_tnb addTarget:self actionForLeftButton:@selector(onBackButton:)];
  [self.view addSubview:i_tnb];
 }
 
 return self;
}
- (void) onBackButton:(id)sender
{
 [self.navigationController popViewControllerAnimated:YES];
}
@end

'iOS' 카테고리의 다른 글

오퍼레이션 큐에서 메모리릭 상황  (0) 2011.02.17
메모리릭 현상(1)  (0) 2011.01.31
iPhone TestCase 생성  (0) 2011.01.18
NSOperation  (0) 2011.01.11
NSOperationQueue  (0) 2011.01.10

Unit Test 연동

Xcode에서는 iPhone의 Unit Test를 지원하기 위해 OCUnit이라는 Unit Testing framework를 xcode 3.0 버전부터 공식적으로 지원하고 있다. 따라서, Xcode의 OCUnit을 통해 생성된 프로젝트에 UnitTest Case를 쉽고 빠르게 생성하고 테스트할 수 있다.
Xcode에서는 Logic Test와 Application Test라는 두 가지 타입의 Unit Test를 지원한다.
Logic Test는 App에서가 아닌 Build Phase에서 Test를 진행하며 소프트웨어의 Logic이나 Algorithm을 테스트하기 위한 방식이다.
단순 메소드나 한개 혹은 여러 개 클래스를 테스트 할 수 있다. 기능의 정상적인 동작을 확인하는 테스트 외에 실제 application과 다른환경을 설정하여 테스트하는 Stress Test도 수행할 수 있다. 
Application Test는 동작하는 application에서 기능을 테스트하는 방식이다. 실제 Device 상에서 테스트가 이루어지기 때문에 iPhone에 있는 Resource를 이용하는 모듈에 대한 Test가 가능하며 User Interface Control의 연결이 잘 설정되었는지 여부도 확인할 수 있다. 
 
 iPhone Unit Test를 위해 사용하는 Logic Test와 Application Test의 설정방법은 다음과 같다.
  • Logic Test 설정방법
    • Xcode에서 Project > New Target메뉴나 Groups & files의 Targets그룹에서 마우스 오른쪽 버튼을 클릭하여 Add> New Target으로 새로운 Target Bundle을 생성함.

                          u1.jpg

    • New Target 템플릿 윈도우에서 Cocoa Touch > Unit Test Bundle을 선택한 후 Next 버튼 클릭함.

                           u2.jpg

    • Target Bundle명을 넣고 finish를 클릭하여 Group and Files의 Targets그룹에 새로 추가된 Target Bundle을 확인함.

                           u3.jpg



 

  • Application Test 설정방법
    • Xcode에서 Group & files의 Targets그룹에 현재 생성된 Target Application을 선택한 후 마우스 오른쪽 버튼을 클릭하여 Duplicate를 선택한 후 새로운 Target Application을 생성함.
    • Application Test는 실제 실행을 위한 Executable Target이 필요함. Duplicate 기능을 이용하면 기존의 프로그램 설정을 그대로 적용하여 실행할 수 있는 Executable Target을 생성할 수 있음.
    • 새로 생성된 Target Application 명 규칙은 <Application_name> + Testing의 형태로 설정함. Target Application 명은 자유롭게 설정이 가능하나 마지막에(suffix) 반드시 Testing을 포함시켜야 함. ex) ApplicationTesting

                          u4.jpg 

    • Xcode에서 Project > New Target메뉴나 Groups & files의 Targets그룹에서 마우스 오른쪽 버튼을 클릭하여 Add > New Target으로 새로운 Target Bundle을 생성함.

                              u5.jpg

    • New Target 템플릿 윈도우에서 Cocoa Touch > Unit Test Bundle을 선택한 후 Next 버튼 클릭함.

                          u6.jpg

 

    • Target Bundle명을 넣고 finish를 클릭하여 Group and Files의 Targets그룹에 새로 추가된 Target Bundle을 확인함.
    • 새로 생성되는 Target Bundle명 규칙은 <Application_name> + Tests의 형태로 설정함. 이름은 자유롭게 설정이 가능하나 마지막에는(suffix) 반드시 Tests을 포함시켜야 함. ex) ApplicationTests

                          u7.jpg

 

 

  • TestCase Class생성방법
    • Group and Files 목록에 그룹을 추가하기 위해서 프로젝트 명에서 마우스의 오른쪽을 클릭하여 Add > New Group 메뉴를 선택하고 Test 클래스가 있을 Group을 생성하고 Group 명을 설정함. Group명은 특별한 규칙이 없이 자유롭게 작성이 가능함.

                          u8.jpg

 

    • 새로 생성한 Group에 마우스 오른쪽 버튼을 클릭하여 Add > New File을 실행하면 New File 템플릿 윈도우에서 Objective-C test case class형식의 파일을 선택 후 Next 버튼을 클릭함.

                         u9.jpg

 

    • 생성할 Test case의 파일 명과 파일 명 바로 아래에 있는 Also create XXX.h 옵션도 함께 선택함. 이때 Targets은 Executable Target이 아닌 Target Bundle (ApplicationTests)만 선택한 후 Finish 버튼을 클릭함.

                          u10.jpg

 

    • 생성한 Test class Group에 새로 생성된 Test Case Class 코드가 추가된 것을 확인할 수 있음.

                          u11.jpg

 

  • Target Dependency 설정
    • Target 그룹의 Target Bundle (ApplicationTests)을 더블 클릭한 후 Target Info 윈도우에서 General 탭을 선택함.

                          u12.jpg

    • Direct Dependencies의 ‘+’ 버튼을 클릭하여 원 Application Target 'OCT'을 선택하여 추가함

                          u13.jpg

 

    • Target 그룹의 Target Application (ApplicationTesting)을 더블 클릭한 후 Target Info 윈도우에서 General 탭을 선택함.

                          u14.jpg

 

    • Direct Dependencies의 ‘+’ 버튼을 클릭하여 Target Bundle 'ApplicationTests'을 선택하여 추가함 

                          u15.jpg

 

    • Products 폴더에서 생성된 Target Bundle 이름의 octest파일(ApplicationTests.octest)을 Target Application(ApplicationTesting)> Copy Bundle Resource로 dragging하여 Copy시켜 생성함.

<Products 폴더에 octest 파일이 빨강색인 경우>
octest 파일의 글자 색이 빨강색으로 나올 경우 Build가 진행되지 않았기 때문으로 Build를 진행시키면 빨강색은 사라짐.

 

 

                        

 

                         u16.jpg

 

    • Xcode 좌측 상단에 있는 설정버튼을 클릭하여 Active Target을 Target Application (ApplicationTesting)으로 선택함.
    • Active Executable 은 Target Application(ApplicationTesting – iPhone Simulator3.1.3)선택함.

                        u17.jpg

 

  • Build 환경 설정 및 Unit Test결과확인
    • Group&files에서 Project와 Target을 더블클릭하면 빌드설정 창이 나타나고, BaseSDK 설정을 Device 모드로 변경함. 
    • UnitTest 코드가 생성되면 소스코드 안에 LigicTest와 ApplicationTest를 수행할 수 있는 샘플 테스트코드가 기본적으로 제공됨. 실제 새로운 테스트코드를 작성할 경우 이 샘플코드는 지우고 사용함.  
    • 샘플코드의 헤더파일에서 정의된 USE_APPLICATION_UNIT_TEST 값을 '1'로 설정하면 testAppDelegate함수가 호출되면서 ApplicationTest 방식의 테스트가 수행됨.
    •  USE_APPLICATION_UNIT_TEST 값을 '0'으로 설정하면 testMath 함수를 호출되며 LogicTest 방식의 테스트가 수행됨.
    • Device가 연결되지 않은 경우에는 USE_APPLICATION_UNIT_TEST 값 설정을 '0'으로 변경하고 Simulator로 logicTest를 수행하고 결과를 확인할 수 있음. 

u29.jpg

 

    • 설정을 모두 마치고 Xcode에서 Build > Build를 수행하여 결과를 확인함.
    • Xcode에서는 Build 시 Unit Test 결과를 Xcode 하단에 함께 표시하고 있음.
      Test 성공 시 ‘Succeeded’라는 메시지가 표시되고 Test 실패 시 ‘Failed’라는 메시지가 표시됨.

                          u20.jpg

    • 표시된 결과 메시지를 클릭하여 Unit Test의 수행된 총 테스트 케이스와 어떤 테스트 케이스에서 성공 및 실패 여부, 테스트케이스 소요시간 등의 상세정보를 확인함.

                          u21.jpg

 

                          u22.jpg

 

 

  •  Unit Test 결과의 CI 연동
    • OCUnit 결과를 JUnit 형태의 xml파일로 변경시켜주는 ocunit2junit.rb 파일을 /usr/bin/ 디렉터리에 추가함
    • xcodebuild clean 명령어를 설정하고 Target은 LogicTest Target Bundle 명으로 설정함.

                         u23.jpg

xcodebuild clean -target "LogicTest Target bundle 명” -configuration Debug

 

    • Target 대상 프로젝트를 수행시키는 xcodebuild 명령어 설정함.

                          u24.jpg

 

                                    xcodebuild -target "LogicTests" -configuration Debug

                                    -sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/

 

    • Hudson CI Build의 Execute Shell에서 xcode build설정 다음에 | /usr/bin/ocunit2junit.rb 으로 설정함. 
      ocunit2junit.rb는 OCunit의 결과파일을 JUnit 형태의 xml 파일로 변경하여 Hudson CI의 JUnit Plug- in을 통해 설정할 수 있는 스크립트 파일임. 

                          u25.jpg

    • Hudson CI의 Publish JUnit test result report을 선택하고 test-reports/*.xml 로 설정함.

                         u26.jpg

    • Build Now를 실행하면 해당 Unit Test 결과 그래프를 확인함.


                   u27.jpg


'iOS' 카테고리의 다른 글

메모리릭 현상(1)  (0) 2011.01.31
Custom UINavigationController  (0) 2011.01.24
NSOperation  (0) 2011.01.11
NSOperationQueue  (0) 2011.01.10
NSNotificationCenter  (0) 2011.01.05

실행순서

start or main -> isFinished -> YES -> stop
                                       -> NO -> suspended


@interface TestQueue : NSOperation {

 NSString * i_Id;
 NSOperationQueue * i_queue;
}

-(id)initWithId:(NSString *)qid inOperationQueue:(NSOperationQueue *) queue;

@end


@implementation TestQueue
-(id)initWithId:(NSString *)qid inOperationQueue:(NSOperationQueue *) queue
{
 if(self=[super init])
 {
  i_Id = qid;
  i_queue = [queue retain];
 }
 
 return self;
}
- (void)main
{
 NSLog(@"[%d] Queue Main : %@",[i_queue operationCount], i_Id);
 return;
}
/*
- (void)start
{
 NSLog(@"Queue Start : %@", i_Id);
}*/
- (void)stop
{
 NSLog(@"Queue Stop : %@", i_Id);
}
- (void)dealloc
{
    [i_queue release];  
 
 [super dealloc];
}
- (void)cancel
{
 NSLog(@"Queue Cancel : %@", i_Id);
 
 [super cancel];
}
- (BOOL)isFinished
{
 NSLog(@"Queue Finished : %@", i_Id);
 
 return YES;
}

@end

'iOS' 카테고리의 다른 글

Custom UINavigationController  (0) 2011.01.24
iPhone TestCase 생성  (0) 2011.01.18
NSOperationQueue  (0) 2011.01.10
NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05


NSOperationQueue

The NSOperationQueue class regulates the execution of a set of NSOperation objects. After being added to a queue, an operation remains in that queue until it is explicitly canceled or finishes executing its task. Operations within the queue (but not yet executing) are themselves organized according to priority levels and inter-operation object dependencies and are executed accordingly. An application may create multiple operation queues and submit operations to any of them.

NSOperationQueue클래스는 NSOperation객체의 집합을 실행을 조절한다. 큐를 추가한 후, 연산의 테스크가 실행하여 끝나던가 취소하기 전까지 큐안에 남아있다. 큐안에 연산은 레벨 순위와 내부연산객체의 의존관계에 따라 조직되고 실행된다. 어플리케이션은 멀티 연산 큐를 생성하고 누구라도 연산을 수행한다 

Inter-operation dependencies provide an absolute execution order for operations, even if those operations are located in different operation queues. An operation object is not considered ready to execute until all of its dependent operations have finished executing. For operations that are ready to execute, the operation queue always executes the one with the highest priority relative to the other ready operations. For details on how to set priority levels and dependencies, see NSOperation Class Reference.

연산은 다른 연산 큐에 위치하고 있지만, 내부연산 의존관계는 연산에 대한 확실한 실행 순서를 제공한다. 연산 객체는 모든 연관된 연산이 끝나기 전까지 실행에 대한 준비를 하지 않는다. 실행을 위해 준비가 되는 연산에 대해 연산 큐는 언제나 다른 준비된 연산에 대한 가장 높은 우선 순위로 실행된다. 우선순위와 의존관계에 대해 자세하고 알고 싶다면 NSOperation 클래스 레퍼런스를 확인해라

You cannot directly remove an operation from a queue after it has been added. An operation remains in its queue until it reports that it is finished with its task. Finishing its task does not necessarily mean that the operation performed that task to completion. An operation can also be canceled. Canceling an operation object leaves the object in the queue but notifies the object that it should abort its task as quickly as possible. For currently executing operations, this means that the operation object’s work code must check the cancellation state, stop what it is doing, and mark itself as finished. For operations that are queued but not yet executing, the queue must still call the operation object’s start method so that it can processes the cancellation event and mark itself as finished.

큐에 추가한 후 연산을 직접 제거하는건 불가능하다. 이 연산은 테스크가 끝났다고 알리기 전까지 큐에 남아있다. 태스크 종료는 연산이 완료를 반드시 의미하지 않다. 연산 취소가능하다. 연산객체의 취소는 큐안에 객체가 떠나며 가능한 빠르게 태스크에 대해 거부됨을 객체에 알린다. 최근 실행하는 연산에 대해 객체의 작업이 어떤 이유로 멈추었는지 취소상태를 확인하는 코드가 필요하다. 아직 실행되지 않은 기다리고 있는 연산에 대해, 큐는 연산객의 시작 메소드가 호출되도록 이벤트 취소와 종료 상태를 진행 할수 있다

Operation queues usually provide the threads used to run their operations. In Mac OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations. In Mac OS X v10.5, however, operations are executed on separate threads only if their isConcurrent method returns NO. If that method returns YES, the operation object is expected to create its own thread (or start some asynchronous operation); the queue does not provide a thread for it.

연산 큐는 보통 그들의 연산 실행에 사용되는 스레드를 제공한다. Mac OS X 10.6, 이후 버전은 연산 큐는 연산들의 실행핼을 초기화 시키는 libdispatch라이브러리를 사용한다. 그 결과 병행이나 비병행 연산으로 디자인이 되어있더라도 연산은 언제나 분리된 스레드 상에서 실행되어진다. 하지만 10.5에서 연산은 오직 병행 메소드 결과가 NO 일때 분리된 스레드로 수행이 된다. 만약 메소드의 결과가 YES인 경우 연산 객체는 고유한 스레드가 생성될 (이거나 비동기 연산 시작할때) 것이다.

예제

 @interface testObj : NSOperation
{
 
}

@end

NSOperationQueue    *i_Queue;

testObj *qObj = [[testObj alloc]init];

[i_Queue addOperation:qObj];

[qObj release];

'iOS' 카테고리의 다른 글

iPhone TestCase 생성  (0) 2011.01.18
NSOperation  (0) 2011.01.11
NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04


NSNotificationCenter

An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program. An NSNotificationCenter object is essentially a notification dispatch table.

NSNotificationCenter 객체는 프로그램내 broadcasting에 대한 메커니즘에을 제공한다.
이 객체는 통지처리 테이블(notification dispatch table)을 기본으로 한다

Objects register with a notification center to receive notifications (NSNotification objects) using the addObserver:selector:name:object: or addObserverForName:object:queue:usingBlock: methods. Each invocation of this method specifies a set of notifications. Therefore, objects may register as observers of different notification sets by calling these methods several times.

객체는 addObserver:selector:name:object: 나 addObserverForName:object:queue:usingBlock: methods를
사용하여 NSNotificationCenter 객체를 알림센터(notification center)에 등록한다

When an object (known as the notification sender) posts a notification, it sends an NSNotification object to the notification center. The notification center then notifies any observers for which the notification meets the criteria specified on registration(지정된 표준 등록) by sending them the specified notification message, passing the notification as the sole argument.
 
객체(notification sender로 알려진..) 알림을 발송 할 때 알림센터에 NSNotification 객체를 보낸다.

A notification center maintains a notification dispatch table which specifies a notification set for a particular observer. A notification set is a subset of the notifications posted to the notification center. Each table entry contains three items:

알림센터는 특별한 observer에 대한 알림집합이 명시된 알림 발송 테이블을 유지한다. 알림집합은 알림센터에 보내지는 알림의 하위집합이다. 각 테이블 엔트리는 3가지 항목을 포함한다

Notification observer: Required. The object to be notified when qualifying notifications are posted to the notification center.

Notification name: Optional. Specifying a name reduces the set of notifications the entry specifies to those that have this name.

Notification sender: Optional. Specifying a sender reduces the set of notifications the entry specifies to those sent by this object.

Table 1 shows the four types of dispatch table entries and the notification sets they specify. (This table omits the always present notification observer.)


defaultCenter

Returns the process’s default notification center.

+ (id)defaultCenter
Return Value

The current process’s default notification center, which is used for system notifications.

Availability
  • Available in iOS 2.0 and later.

예제

옵저버 등록

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self  // 센터에 옵저버 등록 
                            selector:@selector(reachabilityChanged:)   // 옵저버가 가지고 있는 메소드 셀렉터 -> self(appDelegate)의 reachabilityChanged: 호출
                               name:Na_STR_REACHABILITY_NOTIFICATION // 메세지를 보내서 알리고 싶은 노티피케이션명을 지정
                               object:nil // 특정 객체가 포스팅한 통지만 받고 싶을 때 지정
];


옵저버 삭제

[removeObserver:@selector(reachabliityChanged)]





----NotificationObj.h--------
#import <Foundation/Foundation.h>

@interface NotificationObj : NSObject {

}
- (void) callChange;
- (void) regNotification;
- (void) postNotification;

@end


----NotificationObj.m--------
#import <Foundation/Foundation.h>
#import "NotificationObj.h"

@implementation NotificationObj

- (void) regNotification {
 
 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
 
 // 네트워크 연결 상태가 변경할 때 마다 노티피케이션을 포스트하기 위해 defaultCenter에 옵저버 등록
 [defaultCenter addObserver:self
       selector:@selector(callChange) 
        name:@"CALL_CHANGE"  
      object:nil];
}

- (void) postNotification {
 
 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
 [defaultCenter postNotificationName:@"CALL_CHANGE"  
        object:self];
}

- (void) callChange {
 
 NSLog(@"Notification Post");
}

@end                   

----main.m--------
#import <Foundation/Foundation.h>
#import "NotificationObj.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

 NotificationObj * nObj = [[NotificationObj alloc] init];
   
 [nObj regNotification];
 
 [nObj postNotification];
 
 [pool release];
 
    return 0;
}

'iOS' 카테고리의 다른 글

NSOperation  (0) 2011.01.11
NSOperationQueue  (0) 2011.01.10
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04
NSUserDefaults  (0) 2011.01.04


NSSearchPathForDirectoriesInDomains

NSArray * NSSearchPathForDirectoriesInDomains (
   NSSearchPathDirectory directory,
   NSSearchPathDomainMask domainMask,
   BOOL expandTilde
);

Discussion

Creates a list of path strings for the specified directories in the specified domains.
The list is in the order in which you should search the directories.If expandTilde is YES, tildes are expanded as described in stringByExpandingTildeInPath.For more information on file system utilities, see Locating Directories on the System.

지정된 도메인안에 지정된 디렉토리에 대한 경로 문자열의 리스트를 생성 한다. 리스트는 디렉토리를 찾는 곳이다.
만약 expandTilde가 YES라면 tildes는 stringByExpandingTildeInPath안에 명시된 것 거럼 확장된다.
파일 시스템 유틸에 대해 좀 더 정보를 원한다면 Locating Dirctories on the System을 보라

NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);    
NSString *cacheDirectory = [paths objectAtIndex:0];

결과 : /Users/.../Library/Application Support/iPhone Simulator/4.2/Applications/DD5D66BF-AA44-4B03-A479-1423B1930444/Library/Caches

'iOS' 카테고리의 다른 글

NSOperationQueue  (0) 2011.01.10
NSNotificationCenter  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04
NSUserDefaults  (0) 2011.01.04
IPhon Welcome Image  (0) 2011.01.04
Reachability

Reachability  아이폰과 아이팟터치의 네트워크 상태를 모니터하는 SystemConfiguration framework를 사용하는 데모 샘플이다.
이 예제는 IP routed와 트래픽이 EDGE나 3G와 같은 WWAN인터페스를 통해 route되는 방법을 설명하였다.

http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

SCNetworkReachability

SCNetworkReachability 인터페이스는 시스템의 현재 네트워크 상태와 타겟 호스트의 도달가능성을 결정하는 응용프로그램을 가능하게 한다.

네트워크 스택안에 있는 응용프로그램에 의해 보내진 데이터 패킷이 로컬 장비를 떠나게 될때 도달가능한지 결정한다. Reachability는 데이터 패킷이 실제로 호스트에 받았는지 보장하지 않는다.

SCNetworkReachability 프로그래밍 인터페이스는 비동기와 동기 모델을 지원한다. 동기 모델에서 SCNetworkReachabilityGetFlags 함수에 의해 도달 상태를 얻을 수 있다. 비동기 모델에서는 클라이언트 객체의 스레드의 run loop상에서 SCNetworkReachability 객체를 스케줄 할수 있다.

클라이언트는 원격 호스트 reachability 상태가 변할 때 알림을 받은 콜백 함수에 적용된다

'iOS' 카테고리의 다른 글

NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
NSUserDefaults  (0) 2011.01.04
IPhon Welcome Image  (0) 2011.01.04
메소드 함수 가변인수 정의  (0) 2010.12.28

목적 : NSUserDefaults 클래스는 시스템과 의사소통하는 계획된 인터페이스를 제공한다.(환경값 저장)
예 : 사용자 화면 출력 단위, 자동 저장여부

방법
저장 : [[NSUserDefaults standardUserDefaults] setInteger:KEY_VALUE forKey:KEY_NAME];
읽기 : [[NSUserDefaults standardUserDefaults] integerForKey:KEY_NAME];

'iOS' 카테고리의 다른 글

NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04
IPhon Welcome Image  (0) 2011.01.04
메소드 함수 가변인수 정의  (0) 2010.12.28
아이폰 앱이 처음 실행될때 화면에 보이는

스플래쉬 애니메이션 이미지는 설정이 따로 있는게 아니라 Resources 폴더내

Default.png 이름으로 설정하면 된다.

'iOS' 카테고리의 다른 글

NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04
NSUserDefaults  (0) 2011.01.04
메소드 함수 가변인수 정의  (0) 2010.12.28

사용목적 : printf와 같이 동일 객체 받아들일 수 있는 가변 인수를 생성할때

메소드 정의

@interface 클래스명
- (반환타입) 메소드명 : (인자 타입)가변인자명, ... NS_REQUIRES_NIL_TERMINATION;
@end


NS_REQUIRES_NIL_TERMINATION
-> 가변 인수의 마지막에 NULL이나 nil을 두어 인수의 끝을 표시, NULL을 입력 못할 경우 오작동
-> 함수의 프로토타입 선언 끝에 매크로를 기술하여 이런 잠재 위험에 대처


메소드 구현

@implementation 클래스명
-(반환타입) 메소드명 : 가변인자, ...
{
va_list varglist;       // 가변인자를 리스트 형으로 받을 임시 객체

va_start(varglist, 가변인자);   // 가변인자를 리스트형으로 변환

while((item = va_arg(varglist, 인자타입)) != nil) {
// 지정한 인자타입의 item을 사용
}

va_end(varglist);   // 가변인자 종료
}
@end


'iOS' 카테고리의 다른 글

NSNotificationCenter  (0) 2011.01.05
NSSearchPathForDirectoriesInDomains  (0) 2011.01.05
Reachability & SCNetworkReachability  (0) 2011.01.04
NSUserDefaults  (0) 2011.01.04
IPhon Welcome Image  (0) 2011.01.04

+ Recent posts