Storyboard 에서 iPad용 UI를 만들고 있는데, 가로/세로에 대해 서로 다른 UI를 만들어야 하는 경우가 생겼다.

문제는 iPad에서는 iPhone처럼 Regular/Compact을 조절해서는 안된다는 것.

아래와 같이 해결했음. 


UITraitCollection을 이용해서 화면에 따라 모드를 지정해 준다.


Storyboard 상에서는 아래 모드로 작업을 해두고

세로를 작업할 때는 Width:Any, Height:Regular 로 하고,

가로를 작업할 때는 Width:Regular, Height:Compact로 했음.


RootViewController나 ParentViewController에 아래 코드를 추가하면 된다는데, 나는 NavigationController에 해 줬음.


- (UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController

{

    UITraitCollection *wRegular = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];

    UITraitCollection *hCompact = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassCompact];

    UITraitCollection *horizontal = [UITraitCollection traitCollectionWithTraitsFromCollections:@[wRegular, hCompact]];

    

    UITraitCollection *wAny = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];

    UITraitCollection *hRegular = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];

    UITraitCollection *portrait = [UITraitCollection traitCollectionWithTraitsFromCollections:@[wAny, hRegular]];

    

    if (CGRectGetWidth(self.view.bounds) < CGRectGetHeight(self.view.bounds))

    {

        return portrait;

    }

    else

    {

        return horizontal;

    }

}


참조 URL : http://stackoverflow.com/a/28268200

Posted by 프리지크
:

* Audio route 변경 시 Notification 수신 방법. (예. Headphones plugged/unplugged) 

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChanged:) name:AVAudioSessionRouteChangeNotification object:nil];


- (void)routeChanged:(NSNotification *)notification

{

   NSNumber *reason = [notification.userInfo objectForKey:AVAudioSessionRouteChangeReasonKey];

   

   if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {

   } else if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {       

   }

}


   - 연관 Notification : AVAudioSessionSilenceSecondaryAudioHintNotification, AVAudioSessionMediaServicesWereLostNotification, AVAudioSessionMediaServicesWereResetNotification, AVAudioSessionInterruptionNotification

Posted by 프리지크
:

* Headphone 이용 시 이벤트 수신 방법.

   // Headphones의 played/paused event 수신. (예. Apple EarPods 일 경우, Center Button 한번 클릭)

   // !!특이점

   //   - Apple EarPods 일 경우, togglePlayPauseCommand를 수신.

   //   - 일반 Bluetooth Headphones 일 경우, 아래의 playCommand/pauseCommand를 수신. (왜??? ;;;;)

   MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

   [commandCenter.togglePlayPauseCommand addTarget:self action:@selector(command)];

   

   // Headphones의 played event 수신

   commandCenter.playCommand.enabled = YES;

   [commandCenter.playCommand addTarget:self action:@selector(playCommand)];

   

   // Headphones의 paused event 수신

   commandCenter.pauseCommand.enabled = YES;

   [commandCenter.pauseCommand addTarget:self action:@selector(pauseCommand)];

   

   // Headphones의 Next track event 수신. (예. Apple EarPods 일 경우, Volume up 버튼을 두번 클릭)

   commandCenter.nextTrackCommand.enabled = YES;

   [commandCenter.nextTrackCommand addTarget:self action:@selector(nextTrackCommand)];

   

   // Headphones의 Previous track event 수신. (예. Apple EarPods 일 경우, Volume down 버튼을 두번 클릭)

   commandCenter.previousTrackCommand.enabled = YES;

   [commandCenter.previousTrackCommand addTarget:self action:@selector(previousTrackCommand)];


또는, 


UIResponse를 상속받는 AppDelegate 에서 아래 메소드를 통해 이벤트를 받을 수 있음.


- (void)remoteControlReceivedWithEvent:(nullable UIEvent *)event


Posted by 프리지크
:

  예를 들어, 문자열을 4자리씩 끊어야 할 경우,


    NSString *number = @"1234567890";

    NSError *error = NULL;

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@".{1,4}" options:0 error:&error];

    NSArray *matches = [regex matchesInString:number options:0 range:NSMakeRange(0, [number length])];


    for (NSTextCheckingResult *match in matches)

    {

        NSLog(@"%@", [number substringWithRange:match.range]];

    }


결과는

 1234

 5678

 90


Posted by 프리지크
:

XCode6 시뮬레이터에서 간혹(자주?) 한글 키보드가 안나오는 경우가 있다.

아래 설정을 해 주면 나온다.

그 전에 설정에서 키보드의 언어는 추가가 되어 있어야 한다.




Posted by 프리지크
:

간혹 XCode의 디버그창에서 포인터로 된 변수의 경우 메모리에 직접 접근해서 값을 봐야하는 경우가 있습니다. 


1. 우선 관련 라인에 브레이크 포인트가 지정된 상태에서 디버그 모드가 되어야합니다.



2. 원하는 변수에 대해 마우스 우클릭 또는 Ctrl+클릭을 하게 되면 옵션창이 뜹니다.  View Memory of * 를 선택합니다.



3. 아래와 같이 메모리를 직접 볼 수 있는 화면이 뜹니다.

   1) 현재 창에서 보이는 메모리의 주소를 지정할 수 있습니다. 

    2) 보이는 화면의 페이지 단위로 앞, 뒤 이동을 할 수 있습니다.

    3) 창에서 보이는 Byte의 크기를 지정할 수 있습니다.

    4) 바이트들을 묶음 단위로 볼 수 있습니다. 

    5) 확인 해 봤던 메모리의 위치들의 히스토리입니다.


참고 : https://developer.apple.com/library/mac/recipes/xcode_help-debugger/articles/viewing_memory.html

Posted by 프리지크
:

UIWebView에서 내부 웹페이지의 크기를 알고 싶을 때.


- 해당 웹뷰 객체 내부의 scrollView를 이용하면 됨.


  예. webView.scrollView.contentSize.width

       webView.scrollView.contentSize.height


  참고. 해당  scrollView의 속성은 readonly 임.

Posted by 프리지크
:

UIWebView에서 불려진 웹 페이지에 확대/축소 기능을 넣기


  - scalesPageToFit 을 YES로 설정해준다.


끝.

Posted by 프리지크
:

XCode에서 클래스 등을 만들기 위해 파일을 새로 만들면 상단에 아래와 같은 주석이 기본으로 만들어진다.


//  

// TestViewController.m

// TestProject

//

// Created by reddolphin on 13. 12. 5

// Copyright (c) 2012 __MycompanyName__. All rights reserved.

//


최근 Doxygen Document를 만들기 위해서 주석문의 포맷을 변경할 필요가 있었다.

파일을 만들고 위의 기본 형식을 Doxygen document으로 바꿔줄려니 매번 번거롭게 해 줘야 해서 이 참에 기본 포멧을 바꿔줬다.


기본 포멧을 바꿔줄려면 "__FILEBASENAME__.h"와 "__FILEBASENAME__.m"을 바꿔줘야 한다.

이 둘의 위치는 아래 순서로 찾을 수 있다.


1. Finder > Application 에서 XCode의 '패키지 내용 보기'를 해서 아래 경로까지 들어가보면 설정 파일들이 있다.


  1) 패키지 내용 보기 (현재 iMac에는 Xcode 5와 Xcode4.6.3이 같이 설치되어 있기에 두개가 보인다. 난 Xcode 4.6.3만 수정할 거다.)


  2) 아래 경로 우측을 보면 iPhoneOS와 MacOSX가 있는데, 난 iPhone을 개발하고 있음으로 iPhoneOS 선택.


  3) 좀 더 들어간다.


  * 전체 경로를 보자면 아래와 같다. 

    /Applications/Xcode 2.app/Contents/Developer/Platforms/iPhoneOS.platform

/Developer/Library/Xcode/Templates/File Templates/Cocoa Touch


  4) 해당 경로 아래에 있는 __FILEBASENAME__.m/.h에 있는 내용을 doxygen document를 위해 아래와 같이 수정하였다. 


/**

 * ___PROJECTNAME___

 *

 * @file   ___FILENAME___

 * @brief

 * @Created by ___FULLUSERNAME___ on ___DATE___.

 *

 * ___COPYRIGHT___

 */ 


  그런데, 하위 폴더들을 보면 각 클래스의 종류에 따라 __FILEBASENAME__.m/.h 가 무지 많다.

  ('난 시간 많은 사람~.'이라면 하나하나 다 바꿔줘도 된다. )


2. 참고하다보니 Sublime Text 2라는 멋진 에디터가 있더라. 이 에디터로 해당 디렉토리 밑에 있는 파일들에서 일치하는 부분을 한번에 바꿔줄 수 있다.

  1) 우선 Sublime Text 2가 없으면 설치해준다. (유료다. 비싸다. 그런데 사용은 할 수 있다.)

      URL : http://www.sublimetext.com/


  2) Find > Find in Files 를 선택한다.


  3) 아래 부분에 관련 정보를 넣고 Find를 하면 찾아진 부분과 파일들을 보여주는데, 한번 확인 한 뒤에 Replace를 해서 주석문을 교환해주었다. 

     - Find : 찾고자하는 문자열

     - Where : 대상 폴더 지정. 

                    나는 XCode 4.6.3에 있는 부분만 바꿔주기 위해서 위에 찾은 경로를 그대로 넣었다.

 ( /Applications/Xcode 2.app/Contents/Developer/Platforms/iPhoneOS.platform

/Developer/Library/Xcode/Templates/File Templates/Cocoa Touch )

     - Replace : 새로운 문자열. 


   * 참고로 경로는 아래와 같이 알 수 있다.


  4) 아래와 같이 검색 결과가 나왔다.


  5) Replace를 하고 나니 수정이 되었다.


  6) 그리고, 프로젝트에 새로운 파일을 생성해보니 잘 만들어진다. 그런데, Copyright 앞에 공백이 들어가 있다. 왜지. ㅠㅠ 다시 만들어야겠다.



- 참고 : http://unlimitedpower.tistory.com/66

Posted by 프리지크
:

iOS에서 Push Notification을 받았을 때 처리하는 방법은 크게 3가지가 있다.


1) 실행 중이 아닌 상태에서 노티를 받았을 때,

    application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 에서 처리.

   

2) 실행 중이며 Foreground 상태 일 때, 

application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo


3) 실행 중이며 Background 상태 일 때, 

application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo


각각의 예를 보자면, 

1)번의 경우, 최초에 한번 실행되는 didFinishLaunchingWithOptions에서 처리.
   예)  

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

   NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];


    if(userInfo != nil)

    {

        [self application:application didReceiveRemoteNotification:userInfo];

    }

 

    // ....

}


2), 3)번의 경우에서 Foreground와 Background의 상태에 따라서 처리를 다르게 할려면 UIApplicationState를 이용하면 된다.


typedef NS_ENUM(NSInteger, UIApplicationState) {

    UIApplicationStateActive,               // Foreground 상태에서 앱이 실행되고 있을 때.   

    UIApplicationStateInactive,             // Background 등의 상태에서 Foreground 상태로 바뀔 때.

    UIApplicationStateBackground        // Background 상태에서 실행 될 때.

} NS_ENUM_AVAILABLE_IOS(4_0);


예)

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

{

    

    if (application.applicationState == UIApplicationStateActive)

    {

        // ....

    }

    else 

    {

        // ....

    }

}



------------------

참고

 - http://situee.blogspot.kr/2013/08/ios-handle-remote-push-notification.html   - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/econst/UIApplicationStateInactive

Posted by 프리지크
:

BLOG main image
인생에서는 찾고, 노력하고, 희생할 각오가 되어 있는 것만 얻을 수 있다. (조시 매슈 애덤스) by 프리지크

공지사항

카테고리

분류 전체보기 (121)
끄적끄적 (16)
좋은 글 (9)
자료 (19)
런닝&피트니스 (18)
기술 (43)
iOS (29)
Android (1)
기타 (7)
기사 스크랩 (1)
내가 본 공연 후기 (1)
내가 가 본 맛집 (5)
괜찮아 보이는 펜션들 (4)
(4)
한장한장 (0)
비공개 스크랩 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :