http://blog.naver.com/PostView.nhn?blogId=obricko&logNo=40171589651


1. 애플 사이트에서 푸쉬 인증서 만듬 ->aps_development.cer 파일들..


2. 키체인에서 자신의 프라이벗키 빼오기..->열쇠모양의 그 키만 내보내기로 가져옴..여기선 mykey.p12로 이름지음..


3. 콘솔명령어..


openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM


openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem


openssl pkcs12 -export -inkey mike.pem -in aps_development.pem -out 완성인증서명.p12


위의 “완성인증서명.p.12”가 최종적으로 만들어진 인증서임..


개발용 배포용 둘다 요렇게 만들면 제대로 보내짐..

(자바 1.6에서는 굳이 안해도 되지만..1.7에서는 꼭 이걸 해줘야 함..)

'컴퓨터 > 아이폰' 카테고리의 다른 글

uiscrollview에 관한것들..  (0) 2015.01.19
nndate에 관한 유용한 정보  (0) 2015.01.15
아이폰 언어 나라 값 가져오기  (0) 2015.01.05
아이폰 파일 매니져  (0) 2014.02.18
mov 파일 mp4로 변환하기  (0) 2013.11.20
      
Posted by k_ben


UIScrollView에 UIWebView, UITableView를 서브뷰로 추가할 경우 터치 이벤트로 인한 오동작이 발생할 수 있으므로 이런 방식의 구현은 피해야한다.


ScrollView content
01
// Content Offset
02
[scrollView setContentOffset:CGPointMake(100.0f, 100.0f)];
03
CGPoint offset = [scrollView contentOffset];
04
 
05
// Content Size
06
CGSize size = [scrollView contentSize];
07
scrollView.contentSize = CGSizeMake(320, 480);
08
 
09
// Content Inset
10
// Content 상하에 여백을 추가한다.
11
scrollView.contentInset = UIEdgeInsetsMake(64.0,0.0,44.0,0.0);


Scrolling
01
// 스크롤 설정
02
scrollView.scrollEnabled = YES;
03
 
04
// 수직/수평 한 방향으로만 스크롤 되도록 설정
05
scrollView.directionalLockEnabled = YES;
06
 
07
// 상태바를 클릭할 경우 가장 위쪽으로 스크롤 되도록 설정. scrollViewDidScrollToTop: 델리게이트 메소드로 적절한 처리를 해 주어야 한다.
08
scrollView.scrollsToTop = YES;
09
 
10
// 특정 사각 영역이 뷰에 표시되도록 오프셋 이동
11
[scrollView scrollRectToVisible:CGRectMake(50.0, 50.0, 100.0, 100.0) animated:YES];
12
 
13
// 페이징 설정
14
scrollView.pagingEnabled = NO;
15
 
16
// 스크롤이 경계를 넘어섰다가 다시 복귀했는지 판별
17
if (scrollView.bounces) {
18
    NSLog(@"Bounce");
19
}
20
 
21
// 스크롤이 경계에 도달하면 바운싱효과를 적용
22
scrollView.alwaysBounceHorizontal = YES;
23
scrollView.alwaysBounceVertical = YES;
24
 
25
// 스크롤뷰를 터치할 경우 컨텐츠 내부의 뷰에 이벤트 전달
26
[scrollView touchesShouldBegin:touches withEvent:evt inContentView:contentInView];
27
[scrollView touchesShouldCancelInContentView:contentInView];
28
 
29
// 터치이벤트가 발생할 경우 딜레이를 두고 touchesShouldBegin:withEvent:inContentView: 메소드를 호출
30
scrollView.delaysContentTouches = YES;
31
 
32
// 감속 속도 조절
33
scrollView.decelerationRate = UIScrollViewDecelerationRateFast; // or UIScrollViewDecelerationRateNormal
34
 
35
// 스크롤을 하기 위해 뷰를 터치했는지 판별
36
if (scrollView.tracking) {
37
    NSLog(@"User has touched the content view but might not have yet have started dragging it");
38
}
39
 
40
// 스크롤이 시작되었는지 판별
41
if (scrollView.dragging) {
42
    NSLog(@"Dragging or Scrolling....");
43
}
44
 
45
// 스크롤이 종료되고 감속중인지 판별
46
if (scrollView.decelerating) {
47
    NSLog(@"User isn't dragging the content but scrolling is still occurring");
48
}
49
 
50
// 스크롤 바 스타일
51
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
52
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
53
scrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault;
54
 
55
// 스크롤 바 표시
56
scrollView.showsHorizontalScrollIndicator = YES;
57
scrollView.showsVerticalScrollIndicator = YES;
58
 
59
// 특정 시점에 스크롤바 표시
60
[scrollView flashScrollIndicators];
61
 
62
// 스크롤 바 위치 설정
63
scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0);


Zooming & Panning
01
// 특정 영역을 스크롤뷰에 꽉 차도록 확대/축소 한다.
02
[scrollView zoomToRect:CGRectMake(0.0, 0.0, 20.0, 20.0) animated:YES];
03
 
04
// 현재 줌 배율
05
float fZoomScale = scrollView.zoomScale;
06
 
07
// 줌 배율 설정
08
scrollView.minimumZoomScale = 0.2;
09
scrollView.maximumZoomScale = 10.0;
10
[scrollView setZoomScale:3.0 animated:YES];
11
 
12
// 스크롤 뷰가 바운싱되었는지 판별
13
if (scrollView.zoomBouncing) {
14
    NSLog(@"The scroll view is zooming back to a minimum or maximum zoom scaling value");
15
}
16
 
17
// 스크롤 뷰가 줌 중인지 판별
18
if (scrollView.zooming) {
19
    NSLog(@"User is making a zoom gesture");
20
}
21
 
22
// 바운싱 줌 활성화
23
scrollView.bouncesZoom = YES;


UIScrollViewDelegate
view sourceprint?
01
#pragma mark -
02
#pragma mark UIScrollViewDelegate Protocol Methods
03
// 스크롤뷰가 스크롤 된 후에 실행된다.
04
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
05
{
06
}
07
 
08
// 스크롤뷰가 스크롤 되기 직전에 실행된다.
09
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
10
{
11
}
12
 
13
// 스크린을 드래그한 직후에 실행된다.
14
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
15
{
16
    if (decelerate) {
17
        NSLog(@"The scrolling movement will continue, but decelerate, after a touch-up gesture during a dragging operation");
18
    } else {
19
        NSLog(@"Scrolling stops immediately upon touch-up");
20
    }
21
}
22
 
23
// 스크롤뷰가 가장 위쪽으로 스크롤 되기 전에 실행된다. NO를 리턴할 경우 위쪽으로 스크롤되지 않도록 한다.
24
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
25
{
26
    return YES;
27
}
28
 
29
// 스크롤뷰가 가장 위쪽으로 스크롤 된 후에 실행된다.
30
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
31
{
32
}
33
 
34
// 스크롤뷰가 Touch-up 이벤트를 받아 스크롤 속도가 줄어들때 실행된다.
35
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
36
{
37
}
38
 
39
// 스크롤 애니메이션의 감속 효과가 종료된 후에 실행된다.
40
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
41
{
42
}
43
 
44
// 줌 효과를 적용할 뷰를 리턴한다.
45
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
46
{
47
    return webView;
48
}
49
 
50
// 줌이 시작될때 실행된다.
51
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView*)view
52
{
53
 
54
}
55
 
56
// 줌을 완료했을때 실행된다.
57
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
58
{
59
}
60
 
61
// 줌 스케일이 변경된 후에 실행된다.
62
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
63
{
64
}
65
 
66
// 스크롤 애니메이션이 종료된 후에 실행된다.
67
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
68
{
69
}

      
Posted by k_ben


//NSDateFormatter 를 생성한다.
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
//데이트 형식을 지정한다.
[inputFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"];

//inputFormatter 에 지정한 형식대로 NSDate 가 생성된다.
NSDate *formatterDate = [inputFormatter dateFromString:@"1999-07-11 at 10:30"];
//위에 까지가 날짜 생성

//NSDateFormatter 를 생성한다.
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
// 날짜 포맷을 세팅한다.
[outputFormatter setDateFormat:@"HH:mm 'on' EEEE MMMM d"];
//포맷된 형식되로 날짜를 NSString 으로 보여준다. formatterDate 은 위에서 세팅한 날짜 NSDate 값
NSString *newDateString = [outputFormatter stringFromDate:formatterDate];
//로그에 출력해서 본다.
NSLog(@"newDateString %@", newDateString);

부록

 enum {    // date and time format styles
NSDateFormatterNoStyle = kCFDateFormatterNoStyle,
NSDateFormatterShortStyle = kCFDateFormatterShortStyle,
NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,
NSDateFormatterLongStyle = kCFDateFormatterLongStyle,
NSDateFormatterFullStyle = kCFDateFormatterFullStyle
};
 NSDate *date = [NSDate date];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
 NSDateFormatterNoStyle :  ()
NSDateFormatterShortStyle : 10/24/08 (M/d/yy)
NSDateFormatterMediumStyle : Oct 24, 2008 (MMM d, yyyy)
NSDateFormatterLongStyle : October 24, 2008 (MMMM d, yyyy)
NSDateFormatterFullStyle : Friday, October 24, 2008 (EEEE, MMMM d, yyyy)

yyyy : 년도

w : 일년안에서 몇번째 주인지

W : 한달안에서 몇번째 주인지

MM : 월

dd : 일

D : 일년에서 몇번째 일인지

E : 요일 (ex) TuesdayTue

F : 요일을 숫자로 (ex) 2

hh : 시간 ( 12시간 단위로 1-12) 

kk : 시간 (12시간 단위로 0-11)

HH : 시간 (24시간 단위로 1-24)

KK : 시간 (24시간 단위로 0-23)

a : PM 인지 AM 인지

mm : 분

ss : 초. second in minute

SSS : Millisecond

zzzz : General time zone (ex) Pacific Standard TimePSTGMT-08:00

Z : RFC 822 time zone (ex) -800

 

Date and Time PatternResult
"yyyy.MM.dd G 'at' HH:mm:ss z"2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"Wed, Jul 4, '01
"h:mm a"12:08 PM
"hh 'o''clock' a, zzzz"12 o'clock PM, Pacific Daylight Time
"K:mm a, z"0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ"010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"2001-07-04T12:08:56.235-0700


NSDateFormatter가 제공하는 기본 스타일을 사용하지 않고 사용자가 직접 스타일을 지정하여 날짜의 문자열을 얻을 수 있습니다. 아래의 코드를 보시죠 :)

//커스텀 날짜 형식
{
        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"MM/dd/yyyy hh:mma"];
        NSString *dateString = [dateFormat stringFromDate:today];
        NSLog(@"Custom Style Date : %@", dateString);
}
//출력결과
//Custom Style Date : 10/06/2010 03:39PM

위에서 MM, dd, yyyy 와 같은 형식지정자가 어떤 역할을 하는지 알아야 하는데 어디서 그 내용을 알 수 있을까요? 바로 ICU (International Components for Unicode)에서 표준 날짜 형식 지정자를 정해 놓습니다. 여기서 제공하는 문서에서 날짜 형식 패턴 부분을 보면 자세한 설명과 간단한 예제가 있습니다. 아래에 예제를 첨부합니다.

PatternResult (in a particular locale)
yyyy.MM.dd G 'at' HH:mm:ss zzz1996.07.10 AD at 15:08:56 PDT
EEE, MMM d, ''yyWed, July 10, '96
h:mm a12:08 PM
hh 'o''clock' a, zzzz12 o'clock PM, Pacific Daylight Time
K:mm a, z0:00 PM, PST
yyyyy.MMMM.dd GGG hh:mm aaa01996.July.10 AD 12:08 PM


코드를 통해 몇가지 예제를 더 살펴 보겠습니다.

//커스텀 날짜 형식
{
        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
        NSString *dateString = [dateFormat stringFromDate:today];
        NSLog(@"%@", dateString);
}
//출력결과
//Wednesday October 6, 2010
//커스텀 날짜 형식
{
        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"H:mm a, zzz"];
        NSString *dateString = [dateFormat stringFromDate:today];
        NSLog(@"%@", dateString);        
}
//출력결과
//15:39 PM, GMT+09:00

문자열로 표현된 날짜 데이터를 NSDate 객체로 바꾸는 것도 빈번히 일어나는 일입니다. 간한히 예로 들면 100610 이라고 표현된 날짜 문자열을 2010/10/06으로 바꾸고 싶을 때 다음 순서를 따라야 합니다.

  1. 우선 100610 을 NSDateFormatter를 이용하여 NSDate 객체로 변환한다
  2. 변환된 NSDate 를 NSDateFormatter를 이용하여 원하는 날짜 문자열을 얻는다. 
위의 순서대로 작성한 코드를 보겠습니다 :)
//문자열 날짜를 NSDate로 변경하기
{
        NSString *dateStr = @"20020505";
        
        // 1. NSDate로 변경하기
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"yyyyMMdd"];
        NSDate *date = [dateFormat dateFromString:dateStr];
        
        // 2. 원하는 문자열 얻기
        [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
        dateStr = [dateFormat stringFromDate:date];
        
        NSLog(@"%@", dateStr);
}
//출력결과
//Sunday May 5, 2002
문자열로 표현된 날짜 데이터를 NSDate 객체로 변경하여 날짜간의 차이를 얻는 것은 NSDate 의 인스턴스 메소드인 timeIntervalSinceDate 를 이용하면 됩니다


지역에 맞게 날짜 데이터를 출력해 보겠습니다. 우선 현재 사용하고 있는 아이폰이 어떤 지역 설정을 사용하는지 알아보겠습니다. 아래 코드를 보시죠 :)

//아이폰이 현재 사용하고 있는 지역 설정 표시
{
        NSLocale *locale = [NSLocale currentLocale];
        NSLog(@"Current Locale : %@", [locale localeIdentifier]);
}
//출력결과 (시뮬레이터)
//Current Locale : en_US
위 결과를 보시면 현재 지역이 미국으로 설정되어 있습니다. 이를 한국으로 바꾸면 월 이름과 요일 이름이 한글로 출력됩니다. 아래 코드를 보시죠 :)
//지역 설정을 한국으로 변경하기
{
        NSDate *today = [NSDate date];
        
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
        [dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"ko_KR"] autorelease]];
        
        NSString *dateString = [dateFormat stringFromDate:today];
               
        NSLog(@"Today : %@", dateString);
}
//출력결과
//Today : 수요일 10월 6, 2010
NSLocale을 "ko_KR"로 생성하여 NSFormatter에 설정해 주면 됩니다. 그럼 일본어로 표시해 볼까요?
//지역 설정을 일본으로 변경하기
{
        NSDate *today = [NSDate date];
        
        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
        [dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"] autorelease]];
        
        NSString *dateString = [dateFormat stringFromDate:today];       
        
        NSLog(@"Today : %@", dateString);
}
//출력결과
//Today : 水曜日 10月 6, 2010
지금까지 NSDate와 NSDateFormatter에 대해서 알아보았습니다. 해피코딩하세요! 


//date1를 현재 날짜로 설정
    NSDate *date1 = [NSDate date];
    
    //date2을 지정된 날짜로 설정
    NSString *dateStr = @"2015-01-05 23:11:08";
    NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date2 = [dateFormat dateFromString:dateStr];
    
    NSLog(@"Date1  : %@", [dateFormat stringFromDate:date1]);
    NSLog(@"Date2  : %@", [dateFormat stringFromDate:date2]);
    
    //date1과 date2의 차이를 dateComp변수에 저장
    NSDateComponents *dateComp; 
    
    dateComp = [[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:date1 toDate:date2 options:0];
    NSLog(@"Year   : %d", [dateComp year  ]);
    
    dateComp = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit fromDate:date1 toDate:date2 options:0];
    NSLog(@"Month  : %d", [dateComp month ]);
    
    dateComp = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date1 toDate:date2 options:0];
    NSLog(@"Day    : %d", [dateComp day   ]);
    
    dateComp = [[NSCalendar currentCalendar] components:NSHourCalendarUnit fromDate:date1 toDate:date2 options:0];
    NSLog(@"Hour   : %d", [dateComp hour  ]);
    
    dateComp = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit fromDate:date1 toDate:date2 options:0];
    NSLog(@"minute : %d", [dateComp minute]);
    
    dateComp = [[NSCalendar currentCalendar] components:NSSecondCalendarUnit fromDate:date1 toDate:date2 options:0];


      
Posted by k_ben


http://ios.eezytutorials.com/nslocale-by-example.php#.VKn9S8YdfGY


아이폰에 설정된 지역 포맷(언어와 국가 정보)를 가져오려면 NSLocale 클래스를 사용할 수 있다.


지역 포맷 가져오기

NSLocale *currentLocale = [NSLocale currentLocale];


언어 설정 보기

NSString *languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];

// ko (en ...)


국가 설정 보기

NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];

// KR (US ...)


언어와 국가 한번에 가져오기 (locale identifier)

NSString *lcid = [currentLocale localeIdentifier];

// ko_KR (en_US ...)


아이폰에 설정된 언어(지역 포맷 아님)를 가져오려면 다음과 같이 할 수 있다.

NSString *preferredLanguageCode = [[NSLocale preferredLanguages] objectAtIndex:0];

// ko (en ...)


또는 NSUserDefaults 클래스를 사용할 수도 있다.

NSUserDefaults *userDefaults = [standardUserDefaults];

NSArray *languages = [userDefaults objectForKey: @"AppleLanguages"];

NSString *preferredLanguageCode = [languages objectAtIndex:0];

// ko (en ...)




====================================================






Getting and Initializing Locales

- initWithLocaleIdentifier: 

Initializes the receiver using a given locale identifier.

Example

1

2

NSLog(@"%@",[[NSLocale alloc]initWithLocaleIdentifier:@"en_US"]);

        

Output

1

2

2014-04-12 18:57:50.629 iOS-Tutorial[1344:a0b] <__NSCFLocale: 0x9852c00>

        

+ localeWithLocaleIdentifier: 

Returns a locale initialized using the given locale identifier.

Example

1

2

NSLog(@"%@",[NSLocale localeWithLocaleIdentifier:@"en_US"]);

        

Output

1

2

2014-04-12 18:58:26.539 iOS-Tutorial[1359:a0b] <__NSCFLocale: 0xa06ca00>

        

+ systemLocale 

Returns the “root”, canonical locale, that contains fixed “backstop” settings that provide values for otherwise undefined keys.

Example

1

2

NSLog(@"%@",[NSLocale systemLocale]);

        

Output

1

2

2014-04-12 18:58:53.312 iOS-Tutorial[1371:a0b] <__NSCFLocale: 0x8953d90>

        

+ currentLocale 

Returns the logical locale for the current user.

Example

1

2

NSLog(@"%@",[NSLocale currentLocale]);

        

Output

1

2

2014-04-12 18:58:53.312 iOS-Tutorial[1371:a0b] <__NSCFLocale: 0x8953d90>

        

+ autoupdatingCurrentLocale 

Returns the current logical locale for the current user.

Example

1

2

NSLog(@"%@",[NSLocale autoupdatingCurrentLocale]);

        

Output

1

2

2014-04-12 18:59:44.202 iOS-Tutorial[1397:a0b] Auto-updating Locale <nsautolocale: 0x8d6ef20=""> [<__NSCFLocale: 0x895bab0>]

        </nsautolocale:>

Getting Information About a Locale

- displayNameForKey:value: 

Returns the display name for the given value.

Example

1

2

3

NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];

NSLog(@"%@",[locale displayNameForKey:NSLocaleIdentifier value:@"en_US"]);

        

Output

1

2

2014-04-12 19:02:17.306 iOS-Tutorial[1410:a0b] English (United States)

        

- localeIdentifier 

Returns the identifier for the receiver.

Example

1

2

3

NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];

NSLog(@"%@",[locale localeIdentifier]);

        

Output

1

2

2014-04-12 19:02:43.746 iOS-Tutorial[1423:a0b] en_US

        

- objectForKey: 

Returns the object corresponding to the specified key.

Example

1

2

3

NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];

NSLog(@"%@",[locale objectForKey:NSLocaleIdentifier]);

        

Output

1

2

2014-04-12 19:03:55.500 iOS-Tutorial[1444:a0b] en_US

        

Getting System Locale Information

+ availableLocaleIdentifiers 

Returns an array of NSString objects, each of which identifies a locale available on the system.

Example

1

2

NSLog(@"%@",[NSLocale availableLocaleIdentifiers]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

2014-04-12 18:51:30.333 iOS-Tutorial[1269:a0b] (

    "en_IE",

    "ro_MD",

    br,

    "en_GY",

    "es_GT",

    "shi_Tfng_MA",

    mr,

    bs,

    "en_AS",

    ksf,

    "bs_Cyrl",

    "en_PR",

    ms,

    "sr_Latn_ME",

    mt,

    ha,

    "nb_NO",

    "en_SE",

    "en_BZ",

    "pt_BR",

    "or_IN",

    "is_IS",

    "mn_Cyrl_MN",

    "ar_IQ",

    he,

    "it_SM",

    "en_AT",

    bas,

    ckb,

    my,

    "zh_Hans_CN",

    mer,

    "ks_Arab_IN",

    "en_JM",

    "dz_BT",

    "ms_Arab_BN",

    "cy_GB",

    sg,

    "it_CH",

    "teo_KE",

    "de_LU",

    "en_US",

    hi,

    "hu_HU",

    "uz_Latn_UZ",

    "af_NA",

    si,

    "fr_BI",

    "ga_IE",

    mfe,

    "en_CA",

    "ne_IN",

    "rwk_TZ",

    "en_AU",

    sk,

    teo,

    "en_PT",

    "en_NG",

    sl,

    "tk_Latn_TM",

    "tzm_Latn",

    "ee_GH",

    kde,

    sn,

    "dyo_SN",

    "en_SG",

    "mas_TZ",

    so,

    "nyn_UG",

    "br_FR",

    "fr_BJ",

    "es_IC",

    "pt_MZ",

    hr,

    "az_Latn",

    sq,

    sr,

    "sw_KE",

    ca,

    hu,

    "et_EE",

    "lag_TZ",

    "bn_IN",

    nb,

    sv,

    "th_TH",

    "ml_IN",

    "sr_Cyrl_RS",

    sw,

    nd,

    "ta_IN",

    "fr_MQ",

    hy,

    "en_TO",

    "es_AR",

    ne,

    "pt_AO",

    "ne_NP",

    "ar_BH",

    "en_SI",

    "bo_IN",

    "hi_IN",

    seh,

    "de_DE",

    "ko_KP",

    "fr_BL",

    "fr_MR",

    "ca_AD",

    "fa_IR",

    nl,

    "es_PR",

    "en_PW",

    "rn_BI",

    nn,

    "kk_Cyrl",

    "en_DK",

    "sl_SI",

    dua,

    kea,

    "ms_Arab_MY",

    "ig_NG",

    kln,

    yo,

    "fr_DZ",

    "sv_FI",

    "fr_SY",

    "ru_MD",

    "en_ZW",

    "brx_IN",

    "sw_UG",

    "fil_PH",

    cs,

    "pt_GW",

    "bn_BD",

    "de_AT",

    "fr_PF",

    luo,

    "sk_SK",

    "ar_001",

    "es_US",

    "en_SK",

    ta,

    "fr_HT",

    "mk_MK",

    "om_KE",

    "da_DK",

    "en_ME",

    "ko_KR",

    "ff_SN",

    id,

    "en_KY",

    "kde_TZ",

    "shi_Latn",

    cy,

    "en_ES",

    mgh,

    "en_TR",

    "sr_Cyrl_ME",

    te,

    "fr_GN",

    "fo_FO",

    "en_NL",

    ig,

    "it_IT",

    "uk_UA",

    tg,

    "en_DM",

    "bm_ML",

    vai,

    "en_SL",

    ii,

    "en_150",

    ses,

    th,

    ti,

    "en_IM",

    "ru_KZ",

    "fr_MU",

    "iu_Cans_CA",

    "cs_CZ",

    "ar_AE",

    "te_IN",

    tk,

    brx,

    haw,

    "tzm_Latn_MA",

    "so_DJ",

    "uz_Cyrl_UZ",

    "en_BA",

    to,

    "en_MG",

    "ewo_CM",

    "ar_MR",

    "nl_AW",

    "en_IN",

    mgo,

    "sn_ZW",

    "en_CH",

    "en_TT",

    tr,

    is,

    "fr_GP",

    luy,

    "es_NI",

    "pt_TL",

    it,

    "ms_Arab",

    da,

    "kln_KE",

    iu,

    "tk_Latn",

    "en_BB",

    "ar_DZ",

    "ar_SY",

    "ha_Latn",

    "en_MH",

    "mr_IN",

    "en_GB",

    de,

    "fr_GQ",

    "en_NO",

    "ky_KG",

    "pt_PT",

    "fr_RW",

    "nus_SD",

    asa,

    zh,

    "ha_Latn_GH",

    "bo_CN",

    "kam_KE",

    "dua_CM",

    "khq_ML",

    "ur_IN",

    "en_LC",

    "fr_TD",

    "ksb_TZ",

    "gu_IN",

    om,

    jmc,

    "ro_RO",

    "ja_JP",

    "ln_AO",

    "so_ET",

    "en_GD",

    "nl_NL",

    "es_ES",

    "en_VC",

    or,

    "yo_NG",

    "es_PY",

    "mua_CM",

    "fa_AF",

    "en_HK",

    ja,

    "luo_KE",

    twq,

    "en_BE",

    "es_UY",

    "dje_NE",

    "luy_KE",

    naq,

    "si_LK",

    zu,

    "zh_Hans_MO",

    "fr_KM",

    "zh_Hant_HK",

    dz,

    swc,

    "asa_TZ",

    "jgo_CM",

    "az_Cyrl",

    ewo,

    "gv_GB",

    "ti_ER",

    "be_BY",

    "en_IS",

    "en_CM",

    uk,

    "cgg_UG",

    nyn,

    "tr_CY",

    "de_CH",

    "fr_TG",

    "jmc_TZ",

    "ta_LK",

    "so_SO",

    "es_DO",

    "fr_LU",

    "shi_Latn_MA",

    "en_SS",

    "swc_CD",

    "kn_IN",

    "hy_AM",

    "en_IT",

    "en_GG",

    fil,

    "bas_CM",

    "en_TZ",

    "ar_TD",

    ur,

    "bez_TZ",

    "haw_US",

    "fr_VU",

    "tg_Cyrl",

    pa,

    "bs_Latn_BA",

    "ee_TG",

    "ti_ET",

    "sr_Latn_BA",

    "en_GH",

    ee,

    "en_VG",

    "sv_SE",

    "ki_KE",

    "zh_Hans",

    bem,

    uz,

    "ar_YE",

    "fr_NC",

    "seh_MZ",

    "ru_UA",

    "fr_SC",

    "ar_KM",

    "en_ZA",

    "en_GI",

    "mas_KE",

    "nn_NO",

    "ar_EG",

    el,

    "en_RO",

    pl,

    "nl_BE",

    en,

    "uz_Latn",

    eo,

    shi,

    kok,

    mas,

    "fr_FR",

    rof,

    "en_MP",

    "de_BE",

    "hr_BA",

    "ar_EH",

    "es_CL",

    "en_AD",

    es,

    "en_VI",

    ps,

    et,

    "nl_SR",

    "vai_Latn",

    pt,

    eu,

    ka,

    "fr_NE",

    "eu_ES",

    "mgh_MZ",

    "zu_ZA",

    "ar_SA",

    "chr_US",

    cgg,

    "sq_MK",

    lag,

    "az_Latn_AZ",

    "es_VE",

    "ks_Arab",

    "en_HR",

    "el_GR",

    "el_CY",

    "mfe_MU",

    ki,

    vi,

    "en_KE",

    rwk,

    bez,

    kk,

    kl,

    "zh_Hant",

    "fr_CA",

    km,

    "es_HN",

    "agq_CM",

    kn,

    "ii_CN",

    "mn_Cyrl",

    "en_BM",

    ko,

    "sv_AX",

    "ln_CD",

    "en_GM",

    "iu_Cans",

    "fr_MA",

    "es_CO",

    "en_AG",

    "guz_KE",

    ks,

    "es_PA",

    "twq_NE",

    "en_NZ",

    "fr_TN",

    fa,

    "en_US_POSIX",

    "dav_KE",

    "en_WS",

    "lt_LT",

    "en_SZ",

    "ar_SD",

    "rof_TZ",

    "uz_Arab_AF",

    "vi_VN",

    "en_MT",

    kw,

    "yav_CM",

    "ta_MY",

    "ru_KG",

    kab,

    ky,

    ff,

    "en_PG",

    "to_TO",

    "ar_LY",

    jgo,

    "en_HU",

    "af_ZA",

    "en_UG",

    "de_LI",

    fi,

    "es_SV",

    khq,

    gsw,

    "ksf_CM",

    "fr_DJ",

    "en_MU",

    "bs_Latn",

    "ln_CF",

    "ms_Latn",

    "kea_CV",

    "pl_PL",

    "pa_Arab",

    "fr_MC",

    "sr_Cyrl_BA",

    "sr_Latn",

    "en_RU",

    "en_PH",

    saq,

    "ar_PS",

    "fr_CD",

    "bem_ZM",

    "ru_RU",

    "uz_Cyrl",

    "pa_Guru",

    "vai_Vaii",

    "en_FI",

    fo,

    "so_KE",

    "ln_CG",

    "ar_OM",

    "pt_ST",

    "en_KI",

    "kl_GL",

    fr,

    "es_CR",

    "ses_ML",

    tzm,

    "mer_KE",

    xog,

    "xog_UG",

    "nl_SX",

    "en_FJ",

    "ms_Latn_BN",

    "en_MW",

    "ar_MA",

    "pt_MO",

    kam,

    "en_TC",

    af,

    "ar_TN",

    "am_ET",

    "es_PE",

    "sbp_TZ",

    "fr_CF",

    "vun_TZ",

    "fr_RE",

    "ar_JO",

    ebu,

    lg,

    "ha_Latn_NG",

    "lv_LV",

    ak,

    chr,

    "az_Cyrl_AZ",

    dav,

    "en_EE",

    "es_419",

    "ebu_KE",

    "en_CY",

    "fr_MF",

    "en_AL",

    am,

    "en_PK",

    "mgo_CM",

    "fr_CG",

    dje,

    "en_JE",

    "en_LR",

    dyo,

    ln,

    "ak_GH",

    "pa_Guru_IN",

    "ar_DJ",

    "en_BS",

    lo,

    "zh_Hant_TW",

    "lg_UG",

    "ar_KW",

    ar,

    "bs_Cyrl_BA",

    "es_EA",

    "fr_MG",

    "ca_ES",

    as,

    "he_IL",

    "es_CU",

    "en_CZ",

    "en_PL",

    "fr_GA",

    "mg_MG",

    "fr_CH",

    "en_LS",

    lt,

    "my_MM",

    "kk_Cyrl_KZ",

    ga,

    "en_FM",

    lu,

    "ps_AF",

    nmg,

    "es_BO",

    sbp,

    lv,

    vun,

    "fr_YT",

    "km_KH",

    "teo_UG",

    "fr_SN",

    "om_ET",

    "ar_ER",

    "gsw_CH",

    az,

    "es_PH",

    "fi_FI",

    "tr_TR",

    "fr_CI",

    "en_LT",

    "en_UM",

    "sr_Cyrl",

    "ur_PK",

    "hr_HR",

    "nl_CW",

    "en_KN",

    "ms_Latn_MY",

    "ar_IL",

    "en_ZM",

    "es_EC",

    "gl_ES",

    "en_GU",

    gl,

    "nmg_CM",

    "zh_Hant_MO",

    "en_NA",

    "ha_Latn_NE",

    "mt_MT",

    rm,

    "kw_GB",

    "zh_Hans_SG",

    rn,

    ro,

    "rm_CH",

    "saq_KE",

    "vai_Vaii_LR",

    "ka_GE",

    "es_GQ",

    "sr_Latn_RS",

    "en_VU",

    "zh_Hans_HK",

    "en_LV",

    agq,

    gu,

    "lo_LA",

    ru,

    "en_SB",

    gv,

    "en_BW",

    yav,

    "ta_SG",

    "fr_BE",

    "bg_BG",

    "es_MX",

    rw,

    be,

    "nd_ZW",

    "kab_DZ",

    mua,

    "pt_CV",

    bg,

    "tg_Cyrl_TJ",

    "ms_Latn_SG",

    mg,

    "sg_CF",

    "pa_Arab_PK",

    "sw_TZ",

    "en_SC",

    nus,

    "shi_Tfng",

    "ar_QA",

    "naq_NA",

    "fr_BF",

    "rw_RW",

    "as_IN",

    guz,

    ksb,

    "fr_ML",

    mk,

    "kok_IN",

    "sq_AL",

    ml,

    "fr_GF",

    bm,

    "lu_CD",

    "fr_CM",

    bn,

    "ar_LB",

    "id_ID",

    "uz_Arab",

    mn,

    bo,

    "en_FR",

    "en_DE",

    "vai_Latn_LR",

    "ar_SO",

    "ru_BY"

)

        

+ ISOCountryCodes 

Returns an array of NSString objects that represents all known legal country codes.

Example

1

2

NSLog(@"%@",[NSLocale ISOCountryCodes]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

2014-04-12 18:52:34.889 iOS-Tutorial[1290:a0b] (

    AD,

    AE,

    AF,

    AG,

    AI,

    AL,

    AM,

    AO,

    AQ,

    AR,

    AS,

    AT,

    AU,

    AW,

    AX,

    AZ,

    BA,

    BB,

    BD,

    BE,

    BF,

    BG,

    BH,

    BI,

    BJ,

    BL,

    BM,

    BN,

    BO,

    BQ,

    BR,

    BS,

    BT,

    BV,

    BW,

    BY,

    BZ,

    CA,

    CC,

    CD,

    CF,

    CG,

    CH,

    CI,

    CK,

    CL,

    CM,

    CN,

    CO,

    CR,

    CU,

    CV,

    CW,

    CX,

    CY,

    CZ,

    DE,

    DJ,

    DK,

    DM,

    DO,

    DZ,

    EC,

    EE,

    EG,

    EH,

    ER,

    ES,

    ET,

    FI,

    FJ,

    FK,

    FM,

    FO,

    FR,

    GA,

    GB,

    GD,

    GE,

    GF,

    GG,

    GH,

    GI,

    GL,

    GM,

    GN,

    GP,

    GQ,

    GR,

    GS,

    GT,

    GU,

    GW,

    GY,

    HK,

    HM,

    HN,

    HR,

    HT,

    HU,

    ID,

    IE,

    IL,

    IM,

    IN,

    IO,

    IQ,

    IR,

    IS,

    IT,

    JE,

    JM,

    JO,

    JP,

    KE,

    KG,

    KH,

    KI,

    KM,

    KN,

    KP,

    KR,

    KW,

    KY,

    KZ,

    LA,

    LB,

    LC,

    LI,

    LK,

    LR,

    LS,

    LT,

    LU,

    LV,

    LY,

    MA,

    MC,

    MD,

    ME,

    MF,

    MG,

    MH,

    MK,

    ML,

    MM,

    MN,

    MO,

    MP,

    MQ,

    MR,

    MS,

    MT,

    MU,

    MV,

    MW,

    MX,

    MY,

    MZ,

    NA,

    NC,

    NE,

    NF,

    NG,

    NI,

    NL,

    NO,

    NP,

    NR,

    NU,

    NZ,

    OM,

    PA,

    PE,

    PF,

    PG,

    PH,

    PK,

    PL,

    PM,

    PN,

    PR,

    PS,

    PT,

    PW,

    PY,

    QA,

    RE,

    RO,

    RS,

    RU,

    RW,

    SA,

    SB,

    SC,

    SD,

    SE,

    SG,

    SH,

    SI,

    SJ,

    SK,

    SL,

    SM,

    SN,

    SO,

    SR,

    SS,

    ST,

    SV,

    SX,

    SY,

    SZ,

    TC,

    TD,

    TF,

    TG,

    TH,

    TJ,

    TK,

    TL,

    TM,

    TN,

    TO,

    TR,

    TT,

    TV,

    TW,

    TZ,

    UA,

    UG,

    UM,

    US,

    UY,

    UZ,

    VA,

    VC,

    VE,

    VG,

    VI,

    VN,

    VU,

    WF,

    WS,

    YE,

    YT,

    ZA,

    ZM,

    ZW

)

        

+ ISOCurrencyCodes 

Returns an array of NSString objects that represents all known legal ISO currency codes.

Example

1

2

NSLog(@"%@",[NSLocale ISOCurrencyCodes]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

2014-04-12 18:53:04.461 iOS-Tutorial[1303:a0b] (

    ADP,

    AED,

    AFA,

    AFN,

    ALK,

    ALL,

    AMD,

    ANG,

    AOA,

    AOK,

    AON,

    AOR,

    ARA,

    ARL,

    ARM,

    ARP,

    ARS,

    ATS,

    AUD,

    AWG,

    AZM,

    AZN,

    BAD,

    BAM,

    BAN,

    BBD,

    BDT,

    BEC,

    BEF,

    BEL,

    BGL,

    BGM,

    BGN,

    BGO,

    BHD,

    BIF,

    BMD,

    BND,

    BOB,

    BOL,

    BOP,

    BOV,

    BRB,

    BRC,

    BRE,

    BRL,

    BRN,

    BRR,

    BRZ,

    BSD,

    BTN,

    BUK,

    BWP,

    BYB,

    BYR,

    BZD,

    CAD,

    CDF,

    CHE,

    CHF,

    CHW,

    CLE,

    CLF,

    CLP,

    CNX,

    CNY,

    COP,

    COU,

    CRC,

    CSD,

    CSK,

    CUC,

    CUP,

    CVE,

    CYP,

    CZK,

    DDM,

    DEM,

    DJF,

    DKK,

    DOP,

    DZD,

    ECS,

    ECV,

    EEK,

    EGP,

    EQE,

    ERN,

    ESA,

    ESB,

    ESP,

    ETB,

    EUR,

    FIM,

    FJD,

    FKP,

    FRF,

    GBP,

    GEK,

    GEL,

    GHC,

    GHS,

    GIP,

    GMD,

    GNF,

    GNS,

    GQE,

    GRD,

    GTQ,

    GWE,

    GWP,

    GYD,

    HKD,

    HNL,

    HRD,

    HRK,

    HTG,

    HUF,

    IDR,

    IEP,

    ILP,

    ILR,

    ILS,

    INR,

    IQD,

    IRR,

    ISJ,

    ISK,

    ITL,

    JMD,

    JOD,

    JPY,

    KES,

    KGS,

    KHR,

    KMF,

    KPW,

    KRH,

    KRO,

    KRW,

    KWD,

    KYD,

    KZT,

    LAK,

    LBP,

    LKR,

    LRD,

    LSL,

    LSM,

    LTL,

    LTT,

    LUC,

    LUF,

    LUL,

    LVL,

    LVR,

    LYD,

    MAD,

    MAF,

    MCF,

    MDC,

    MDL,

    MGA,

    MGF,

    MKD,

    MKN,

    MLF,

    MMK,

    MNT,

    MOP,

    MRO,

    MTL,

    MTP,

    MUR,

    MVP,

    MVR,

    MWK,

    MXN,

    MXP,

    MXV,

    MYR,

    MZE,

    MZM,

    MZN,

    NAD,

    NGN,

    NIC,

    NIO,

    NLG,

    NOK,

    NPR,

    NZD,

    OMR,

    PAB,

    PEI,

    PEN,

    PES,

    PGK,

    PHP,

    PKR,

    PLN,

    PLZ,

    PTE,

    PYG,

    QAR,

    RHD,

    ROL,

    RON,

    RSD,

    RUB,

    RUR,

    RWF,

    SAR,

    SBD,

    SCR,

    SDD,

    SDG,

    SDP,

    SEK,

    SGD,

    SHP,

    SIT,

    SKK,

    SLL,

    SOS,

    SRD,

    SRG,

    SSP,

    STD,

    SUR,

    SVC,

    SYP,

    SZL,

    THB,

    TJR,

    TJS,

    TMM,

    TMT,

    TND,

    TOP,

    TPE,

    TRL,

    TRY,

    TTD,

    TWD,

    TZS,

    UAH,

    UAK,

    UGS,

    UGX,

    USD,

    USN,

    USS,

    UYI,

    UYP,

    UYU,

    UZS,

    VEB,

    VEF,

    VND,

    VNN,

    VUV,

    WST,

    XAF,

    XAG,

    XAU,

    XBA,

    XBB,

    XBC,

    XBD,

    XCD,

    XDR,

    XEU,

    XFO,

    XFU,

    XOF,

    XPD,

    XPF,

    XPT,

    XRE,

    XSU,

    XTS,

    XUA,

    XXX,

    YDD,

    YER,

    YUD,

    YUM,

    YUN,

    YUR,

    ZAL,

    ZAR,

    ZMK,

    ZMW,

    ZRN,

    ZRZ,

    ZWL,

    ZWR,

    ZWD

)

        

+ ISOLanguageCodes 

Returns an array of NSString objects that represents all known legal ISO language codes.

Example

1

2

NSLog(@"%@",[NSLocale ISOLanguageCodes]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

2014-04-12 18:53:33.619 iOS-Tutorial[1315:a0b] (

    aa,

    ab,

    ace,

    ach,

    ada,

    ady,

    ae,

    af,

    afa,

    afh,

    agq,

    ain,

    ak,

    akk,

    ale,

    alg,

    alt,

    am,

    an,

    ang,

    anp,

    apa,

    ar,

    arc,

    arn,

    arp,

    art,

    arw,

    as,

    asa,

    ast,

    ath,

    aus,

    av,

    awa,

    ay,

    az,

    ba,

    bad,

    bai,

    bal,

    ban,

    bas,

    bat,

    bax,

    bbj,

    be,

    bej,

    bem,

    ber,

    bez,

    bfd,

    bg,

    bh,

    bho,

    bi,

    bik,

    bin,

    bkm,

    bla,

    bm,

    bn,

    bnt,

    bo,

    br,

    bra,

    brx,

    bs,

    bss,

    btk,

    bua,

    bug,

    bum,

    byn,

    byv,

    ca,

    cad,

    cai,

    car,

    cau,

    cay,

    cch,

    ce,

    ceb,

    cel,

    cgg,

    ch,

    chb,

    chg,

    chk,

    chm,

    chn,

    cho,

    chp,

    chr,

    chy,

    ckb,

    cmc,

    co,

    cop,

    cpe,

    cpf,

    cpp,

    cr,

    crh,

    crp,

    cs,

    csb,

    cu,

    cus,

    cv,

    cy,

    da,

    dak,

    dar,

    dav,

    day,

    de,

    del,

    den,

    dgr,

    din,

    dje,

    doi,

    dra,

    dsb,

    dua,

    dum,

    dv,

    dyo,

    dyu,

    dz,

    dzg,

    ebu,

    ee,

    efi,

    egy,

    eka,

    el,

    elx,

    en,

    enm,

    eo,

    es,

    et,

    eu,

    ewo,

    fa,

    fan,

    fat,

    ff,

    fi,

    fil,

    fiu,

    fj,

    fo,

    fon,

    fr,

    frm,

    fro,

    frr,

    frs,

    fur,

    fy,

    ga,

    gaa,

    gay,

    gba,

    gd,

    gem,

    gez,

    gil,

    gl,

    gmh,

    gn,

    goh,

    gon,

    gor,

    got,

    grb,

    grc,

    gsw,

    gu,

    guz,

    gv,

    gwi,

    ha,

    hai,

    haw,

    he,

    hi,

    hil,

    him,

    hit,

    hmn,

    ho,

    hr,

    hsb,

    ht,

    hu,

    hup,

    hy,

    hz,

    ia,

    iba,

    ibb,

    id,

    ie,

    ig,

    ii,

    ijo,

    ik,

    ilo,

    inc,

    ine,

    inh,

    io,

    ira,

    iro,

    is,

    it,

    iu,

    ja,

    jbo,

    jgo,

    jmc,

    jpr,

    jrb,

    jv,

    ka,

    kaa,

    kab,

    kac,

    kaj,

    kam,

    kar,

    kaw,

    kbd,

    kbl,

    kcg,

    kde,

    kea,

    kfo,

    kg,

    kha,

    khi,

    kho,

    khq,

    ki,

    kj,

    kk,

    kkj,

    kl,

    kln,

    km,

    kmb,

    kn,

    ko,

    kok,

    kos,

    kpe,

    kr,

    krc,

    krl,

    kro,

    kru,

    ks,

    ksb,

    ksf,

    ksh,

    ku,

    kum,

    kut,

    kv,

    kw,

    ky,

    la,

    lad,

    lag,

    lah,

    lam,

    lb,

    lez,

    lg,

    li,

    lkt,

    ln,

    lo,

    lol,

    loz,

    lt,

    lu,

    lua,

    lui,

    lun,

    luo,

    lus,

    luy,

    lv,

    mad,

    maf,

    mag,

    mai,

    mak,

    man,

    map,

    mas,

    mde,

    mdf,

    mdr,

    men,

    mer,

    mfe,

    mg,

    mga,

    mgh,

    mgo,

    mh,

    mi,

    mic,

    min,

    mis,

    mk,

    mkh,

    ml,

    mn,

    mnc,

    mni,

    mno,

    mo,

    moh,

    mos,

    mr,

    ms,

    mt,

    mua,

    mul,

    mun,

    mus,

    mwl,

    mwr,

    my,

    mye,

    myn,

    myv,

    na,

    nah,

    nai,

    nap,

    naq,

    nb,

    nd,

    nds,

    ne,

    new,

    ng,

    nia,

    nic,

    niu,

    nl,

    nmg,

    nn,

    nnh,

    no,

    nog,

    non,

    nqo,

    nr,

    nso,

    nub,

    nus,

    nv,

    nwc,

    ny,

    nym,

    nyn,

    nyo,

    nzi,

    oc,

    oj,

    om,

    or,

    os,

    osa,

    ota,

    oto,

    pa,

    paa,

    pag,

    pal,

    pam,

    pap,

    pau,

    peo,

    phi,

    phn,

    pi,

    pl,

    pon,

    pra,

    pro,

    ps,

    pt,

    qu,

    raj,

    rap,

    rar,

    rm,

    rn,

    ro,

    roa,

    rof,

    rom,

    ru,

    rup,

    rw,

    rwk,

    sa,

    sad,

    sah,

    sai,

    sal,

    sam,

    saq,

    sas,

    sat,

    sba,

    sbp,

    sc,

    scn,

    sco,

    sd,

    se,

    see,

    seh,

    sel,

    sem,

    ses,

    sg,

    sga,

    sgn,

    shi,

    shn,

    shu,

    si,

    sid,

    sio,

    sit,

    sk,

    sl,

    sla,

    sm,

    sma,

    smi,

    smj,

    smn,

    sms,

    sn,

    snk,

    so,

    sog,

    son,

    sq,

    sr,

    srn,

    srr,

    ss,

    ssa,

    ssy,

    st,

    su,

    suk,

    sus,

    sux,

    sv,

    sw,

    swb,

    swc,

    syc,

    syr,

    ta,

    tai,

    te,

    tem,

    teo,

    ter,

    tet,

    tg,

    th,

    ti,

    tig,

    tiv,

    tk,

    tkl,

    tl,

    tlh,

    tli,

    tmh,

    tn,

    to,

    tog,

    tpi,

    tr,

    trv,

    ts,

    tsi,

    tt,

    tum,

    tup,

    tut,

    tvl,

    tw,

    twq,

    ty,

    tyv,

    tzm,

    udm,

    ug,

    uga,

    uk,

    umb,

    und,

    ur,

    uz,

    vai,

    ve,

    vi,

    vo,

    vot,

    vun,

    wa,

    wae,

    wak,

    wal,

    war,

    was,

    wen,

    wo,

    xal,

    xh,

    xog,

    yao,

    yap,

    yav,

    ybb,

    yi,

    yo,

    ypk,

    yue,

    za,

    zap,

    zbl,

    zen,

    zh,

    znd,

    zu,

    zun,

    zxx,

    zza

)

        

+ commonISOCurrencyCodes 

Returns an array of common ISO currency codes 

Converting Between Identifiers

+ canonicalLocaleIdentifierFromString: 

Returns the canonical identifier for a given locale identification string.

Example

1

2

NSLog(@"%@",[NSLocale commonISOCurrencyCodes]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

2014-04-12 18:55:30.609 iOS-Tutorial[1329:a0b] (

    AED,

    AFN,

    ALL,

    AMD,

    ANG,

    AOA,

    ARS,

    AUD,

    AWG,

    AZN,

    BAM,

    BBD,

    BDT,

    BGN,

    BHD,

    BIF,

    BMD,

    BND,

    BOB,

    BRL,

    BSD,

    BTN,

    BWP,

    BYR,

    BZD,

    CAD,

    CDF,

    CHF,

    CLP,

    CNY,

    COP,

    CRC,

    CUC,

    CUP,

    CVE,

    CZK,

    DJF,

    DKK,

    DOP,

    DZD,

    EGP,

    ERN,

    ETB,

    EUR,

    FJD,

    FKP,

    GBP,

    GEL,

    GHS,

    GIP,

    GMD,

    GNF,

    GTQ,

    GWP,

    GYD,

    HKD,

    HNL,

    HRK,

    HTG,

    HUF,

    IDR,

    ILS,

    INR,

    IQD,

    IRR,

    ISK,

    JMD,

    JOD,

    JPY,

    KES,

    KGS,

    KHR,

    KMF,

    KPW,

    KRW,

    KWD,

    KYD,

    KZT,

    LAK,

    LBP,

    LKR,

    LRD,

    LSL,

    LTL,

    LVL,

    LYD,

    MAD,

    MDL,

    MGA,

    MKD,

    MMK,

    MNT,

    MOP,

    MRO,

    MUR,

    MVR,

    MWK,

    MXN,

    MYR,

    MZE,

    MZN,

    NAD,

    NGN,

    NIO,

    NOK,

    NPR,

    NZD,

    OMR,

    PAB,

    PEN,

    PGK,

    PHP,

    PKR,

    PLN,

    PYG,

    QAR,

    RON,

    RSD,

    RUB,

    RWF,

    SAR,

    SBD,

    SCR,

    SDG,

    SEK,

    SGD,

    SHP,

    SKK,

    SLL,

    SOS,

    SRD,

    SSP,

    STD,

    SVC,

    SYP,

    SZL,

    THB,

    TJS,

    TMT,

    TND,

    TOP,

    TRY,

    TTD,

    TWD,

    TZS,

    UAH,

    UGX,

    USD,

    UYU,

    UZS,

    VEF,

    VND,

    VUV,

    WST,

    XAF,

    XCD,

    XOF,

    XPF,

    YER,

    ZAR,

    ZMW

)

        

+ componentsFromLocaleIdentifier: 

Returns a dictionary that is the result of parsing a locale ID.

Example

1

2

NSLog(@"%@",[NSLocale componentsFromLocaleIdentifier:@"en_US"]);

        

Output

1

2

3

4

5

2014-04-12 19:04:58.222 iOS-Tutorial[1459:a0b] {

    kCFLocaleCountryCodeKey = US;

    kCFLocaleLanguageCodeKey = en;

}

        

+ localeIdentifierFromComponents: 

Returns a locale identifier from the components specified in a given dictionary.

Example

1

2

NSLog(@"%@",[NSLocale localeIdentifierFromComponents:@{@"kCFLocaleCountryCodeKey" : @"US",@"kCFLocaleLanguageCodeKey" :@"en"}]);

        

Output

1

2

2014-04-12 19:07:58.044 iOS-Tutorial[1496:a0b] en_US

        

+ canonicalLanguageIdentifierFromString: 

Returns a canonical language identifier by mapping an arbitrary locale identification string to the canonical identifier.

Example

1

2

NSLog(@"%@",[NSLocale canonicalLanguageIdentifierFromString:@"en_US"]);

        

Output

1

2

2014-04-12 19:08:43.992 iOS-Tutorial[1508:a0b] en-US

        

+ localeIdentifierFromWindowsLocaleCode: 

Returns a locale identifier from a Windows locale code.

Example

1

2

NSLog(@"%@",[NSLocale localeIdentifierFromWindowsLocaleCode:1033]);

        

Output

1

2

2014-04-12 19:11:46.200 iOS-Tutorial[1560:a0b] en_US

        

+ windowsLocaleCodeFromLocaleIdentifier: 

Returns a Window locale code from the locale identifier.

Example

1

2

NSLog(@"%u",[NSLocale windowsLocaleCodeFromLocaleIdentifier:@"en_US"]);

        

Output

1

2

NSLog(@"%u",[NSLocale windowsLocaleCodeFromLocaleIdentifier:@"en_US"]);

        

Getting Preferred Languages

+ preferredLanguages 

Returns the user's language preference order as an array of strings.

Example

1

2

NSLog(@"%@",[NSLocale preferredLanguages]);

        

Output

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

2014-04-12 19:12:18.463 iOS-Tutorial[1572:a0b] (

    en,

    fr,

    de,

    "zh-Hans",

    "zh-Hant",

    ja,

    nl,

    it,

    es,

    "es-MX",

    ko,

    pt,

    "pt-PT",

    da,

    fi,

    nb,

    sv,

    ru,

    pl,

    tr,

    uk,

    ar,

    hr,

    cs,

    el,

    he,

    ro,

    sk,

    th,

    id,

    ms,

    "en-GB",

    "en-AU",

    ca,

    hu,

    vi

)

        

Getting Line and Character Direction For a Language

+ characterDirectionForLanguage: 

Returns the character direction for the specified ISO language code.

Example

1

2

NSLog(@"%d",[NSLocale characterDirectionForLanguage:@"fr"]);

        

Output

1

2

2014-04-12 19:13:46.319 iOS-Tutorial[1584:a0b] 1

        

+ lineDirectionForLanguage: 

Returns the line direction for the specified ISO language code.

Example

1

2

NSLog(@"%d",[NSLocale lineDirectionForLanguage:@"fr"]);

        

Output

1

2

2014-04-12 19:14:56.484 iOS-Tutorial[1606:a0b] 3


'컴퓨터 > 아이폰' 카테고리의 다른 글

uiscrollview에 관한것들..  (0) 2015.01.19
nndate에 관한 유용한 정보  (0) 2015.01.15
아이폰 파일 매니져  (0) 2014.02.18
mov 파일 mp4로 변환하기  (0) 2013.11.20
두개의 비디오 합치기  (0) 2013.11.20
      
Posted by k_ben


파일 메니져 가져오기 

NSFileManage * fileManager = [NSFileManager defaultManager];

 
현재 폴더 가져오기

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *currentPath = [fileManager currentDirectoryPath]; 




Documents 폴더 가져오기  

NSFileManager * fileManager = [NSFileManager defaultManager];
NSArray *dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString documentPath = [dirPath objectAtIndex:0]; 

 
현재 폴더 이동

NSFileManage * fileManager = [NSFileManager defaultManager];
NSArray *dirPath = NSSearchPathForDirectoriesInDomains(NSDocument, NSUserDomainMask, YES);

NSString documentPath = [dirPath objectAtIndex:0]; 

if ([fileManager changeCurrentDirectoryPath:documentPath] == NO){
  // 폴더 이동 못함
} else {
 // 폴더 이동함 

 
폴더 생성 

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *newDir = @"/test";
if (fileManager 
createDirectoryAtPath:newDir withIntermediateDirectories:YES attributes:nil error:NULL] ==NO){
  //  newDir 폴더 생성 실패
} else {
  // newDir 폴더 생성 성공 


 폴더 삭제 

NSFileManage * fileManager = [NSFileManager defaultManager]
NSString *delDir = @"/test";
if (fileManager removeItem
AtPath:delDir error:NULL] == NO){
  //  delDir 폴더 삭제 실패
} else {
  // delDir 폴더 삭제 성공 

 
폴더 내의 목록 표시 

NSFileManage * fileManager = [NSFileManager defaultManager];
NSArray *dirPath = NSSearchPathForDirectoriesInDomains(NSDocument, NSUserDomainMask, YES);
NSString *documentPath = [dirPath objectAtIndex:0]; 

NSArray *filelist = [fileManager contentsOfDirectoryAtPath: documentPath error:NULL]; 

 
파일/폴더 속성 정보 확인 

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *attDir = @"/";
NSDictionary *attributes;
attributes = [fileManager attributesOfItemAtPath:attDir error:NULL];

NSLog(@"파일 정보 : %@", [attributes objectForKey:NSFileType]); 


정의된 속성 정보

FOUNDATION_EXPORT NSString * const NSFileType;

FOUNDATION_EXPORT NSString * const NSFileTypeDirectory;

FOUNDATION_EXPORT NSString * const NSFileTypeRegular;

FOUNDATION_EXPORT NSString * const NSFileTypeSymbolicLink;

FOUNDATION_EXPORT NSString * const NSFileTypeSocket;

FOUNDATION_EXPORT NSString * const NSFileTypeCharacterSpecial;

FOUNDATION_EXPORT NSString * const NSFileTypeBlockSpecial;

FOUNDATION_EXPORT NSString * const NSFileTypeUnknown;

FOUNDATION_EXPORT NSString * const NSFileSize;

FOUNDATION_EXPORT NSString * const NSFileModificationDate;

FOUNDATION_EXPORT NSString * const NSFileReferenceCount;

FOUNDATION_EXPORT NSString * const NSFileDeviceIdentifier;

FOUNDATION_EXPORT NSString * const NSFileOwnerAccountName;

FOUNDATION_EXPORT NSString * const NSFileGroupOwnerAccountName;

FOUNDATION_EXPORT NSString * const NSFilePosixPermissions;

FOUNDATION_EXPORT NSString * const NSFileSystemNumber;

FOUNDATION_EXPORT NSString * const NSFileSystemFileNumber;

FOUNDATION_EXPORT NSString * const NSFileExtensionHidden;

FOUNDATION_EXPORT NSString * const NSFileHFSCreatorCode;

FOUNDATION_EXPORT NSString * const NSFileHFSTypeCode;

FOUNDATION_EXPORT NSString * const NSFileImmutable;

FOUNDATION_EXPORT NSString * const NSFileAppendOnly;

FOUNDATION_EXPORT NSString * const NSFileCreationDate;

FOUNDATION_EXPORT NSString * const NSFileOwnerAccountID;

FOUNDATION_EXPORT NSString * const NSFileGroupOwnerAccountID;


파일 존재 확인

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *extDir = @"/test.txt";
if (fileManager fileExistAtPath:extDir] == YES){
  // 파일 존재 
} else {
  // 파일 없음 


 파일 내용 비교

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *firstFile = @"/test.txt";
NSString *secondFile = "@"/my.txt";

if (fileManager contentEqualAtPath:firstFile andPath:secondFile] == YES){
  // 파일 내용 같음 
} else {
  // 파일 내용 다름 
}


파일 이동 또는 이름 변경

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *firstFile = @"/test.txt";
NSString *secondFile = "@"/my.txt";

if (fileManager moveItemAtPath:firstFile toPath:secondFile error:NULL] == YES){
  // 파일 이동/이름 변경 성공
} else {
  // 파일 이동/이름 변경 실패
}

 
파일 복사

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *firstFile = @"/test.txt";
NSString *secondFile = "@"/my.txt";

if (fileManager copyAtPath:firstFile toPath:secondFile error:NULL] == YES){
  // 파일 복사 성공
} else {
  // 파일 복사 실패
}


파일 읽기(NSData 타입)

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *firstFile = @"/test.txt";
NSData * dataBuffer = [fileManager contentsAtPath:firstFile]; 

 
파일 생성(NSData 타입 읽고 쓰기 -복사 기존 파일 존재시 overwrite 된다.)

NSFileManage * fileManager = [NSFileManager defaultManager];
NSString *firstFile = @"/test.txt";
NSData * dataBuffer = [fileManager contentsAtPath:firstFile]; 
NSString *secondFile = @"/my.txt"
[fileManager createFileAtPath:secondFile contents:dataBuffer attributes:NULL]; 


      
Posted by k_ben


http://hagulu.com/134?TSSESSIONhagulucom=61b070e13499ee1c53a5876e284219c8


안드로이드와 호환이 되는 파일 전송을 구현하다 보니 동영상 전송에 문제가 발생했다.

 
일반적으로 아이폰 비디오 레코더를 이용을 하게되면,
mov라를 확장자의 quickTimeMovie라는 방식으로 저장이 되어 진다.
이 파일을 그대로 안드로이드에 전송을 했더니
안드로이드에서는 하드웨어 코덱을 통해서는 재생을 할수가 없었다.
quick time movie 와  mpeg-4는 외부 포멧만 다를뿐 내부의 영상과 음성 코덱은 유사하다.
따라서 빠르게 변환이 가능한 방법이 있지 않을까 하고 찾다가 방법을 찾게 되었다.
바로 iOS 4 부터 지원되는 AssetLibrary를 이용하는 방법이다
이를 통해서 아래와 같이 구현해 보았다.
변환을 원하는 파일의 NSURL 과 저장을 원하는 파일 path의 NSString 을 주면 해당 path에 저장이 되게 된다.
01+ (void) convertVideoQtimeToMpeg4:(NSURL *) videoURL withPath:(NSString*)videoPath {
02    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
03     
04    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
05 
06    if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) {
07        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
08         
09        exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
10         
11        exportSession.outputFileType = AVFileTypeMPEG4;
12         
13        CMTime start = CMTimeMakeWithSeconds(0.0, 600);
14         
15        CMTimeRange range = CMTimeRangeMake(start, [avAsset duration]);
16         
17        exportSession.timeRange = range;
18         
19        [exportSession exportAsynchronouslyWithCompletionHandler:^{
20             
21            switch ([exportSession status]) {
22                     
23                case AVAssetExportSessionStatusFailed:
24                    NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
25                    break;
26 
27               case AVAssetExportSessionStatusCompleted:
28                     NSLog(@"Export Success");
29                     break;
30                     
31                case AVAssetExportSessionStatusCancelled:
32                     
33                    NSLog(@"Export canceled");
34                     
35                    break;
36                     
37                default:
38                     
39                    break;
40                     
41            }
42             
43            [exportSession release];
44             
45        }];
46         
47    }
48}
이 중에서 초기화 부분이 중요한데 presetName 에
아래처럼 AVAssetExportPresetPassthrough 를 지정해 주어야 다른 포멧으로 변환이 가능하다
 
1[[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
아래와 같이 AVAssetExportPresetMediumQuality 와 같은 파라미터를 주고 outputFileType를 AVFileTypeMPEG로 주게 되면 SIGNAL ABORT가 발생하고 죽게 된다.
 
1AVAssetExportSession *exportSession  = [[AVAssetExportSession alloc]initWithAsset:avAsset AVAssetExportPresetMediumQuality];
2 
3exportSession.outputFileType = AVFileTypeMPEG4;
해당 AVAssetExportSession 의 지원되는 output 포멧을 확인하고 싶을때는 AVAssetExportSession 의 supportedFileTypes propert를 통해서 확인해 볼 수가 있다.


추가로 유의 할 것은 이 방식은 asynchronous 이다.

그렇기 때문에 위와 같이 변환을 한 이후에 바로 이를 이용할수 있는것이 아니다
01[exportSession exportAsynchronouslyWithCompletionHandler:^{
02       
03      switch ([exportSession status]) {
04               
05          case AVAssetExportSessionStatusFailed:
06              NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
07              break;
08 
09         case AVAssetExportSessionStatusCompleted:
10               NSLog(@"Export Success");
11               break;
12               
13          case AVAssetExportSessionStatusCancelled:
14               
15              NSLog(@"Export canceled");
16               
17              break;
18               
19          default:
20               
21              break;
22               
23      }
24       
25      [exportSession release];
26       
27  }];
당황하지 않길 바란다 이 소스는 위에 있는 전체 소스의 일부분이다. 

따라서 위 소스와 같이 exportAsynchronouslyWithCompletionHandler 를 등록하여 "AVAssetExportSessionStatusCompleted"를 확인해야 한다.


      
Posted by k_ben


http://www.mindfiresolutions.com/Merging-Two-Videos--iPhoneiPad-Tip--1396.php



Suppose you have two video files with name video1.mp4 and video2.mp4 and want to merge them into a single video programmatically this tip might help you. Follow the instructions given below-
 
First, we need to add following frameworks in our project:
a)AVFoundation  framework 
b)Asset Library framework 
c)Media Player Framework
d)Core Media frame work
 
Then we need to import following in the view controller class :
 

#import <MediaPlayer/MediaPlayer.h>
#import <CoreMedia/CoreMedia.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <AVFoundation/AVBase.h>

@implementation MyVideoViewController

 - (void) mergeTwoVideo

{

    AVMutableComposition* composition = [AVMutableCompositioncomposition];

NSString* path1 = [[NSBundlemainBundle] pathForResource:@"video1"ofType:@"mp4"];

NSString* path2 = [[NSBundlemainBundle] pathForResource:@"video2"ofType:@"mp4"];

 AVURLAsset* video1 = [[AVURLAssetalloc]initWithURL:[NSURLfileURLWithPath:path1] options:nil];

    AVURLAsset* video2 = [[AVURLAssetalloc]initWithURL:[NSURLfileURLWithPath:path2] options:nil];

    AVMutableCompositionTrack * composedTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo 

                                                                      preferredTrackID:kCMPersistentTrackID_Invalid]; 

        [composedTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video1.duration)

                         ofTrack:[[video1 tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]

                          atTime:kCMTimeZero

                           error:nil];

    [composedTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video2.duration) 

                         ofTrack:[[video2 tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 

                          atTime:video1.duration

                           error:nil];

 

 

NSString* documentsDirectory= [selfapplicationDocumentsDirectory];

NSString* myDocumentPath= [documentsDirectory stringByAppendingPathComponent:@"merge_video.mp4"];

NSURL *url = [[NSURL alloc] initFileURLWithPath: myDocumentPath];

     if([[NSFileManagerdefaultManager] fileExistsAtPath:myDocumentPath])

    {

        [[NSFileManagerdefaultManager] removeItemAtPath:myDocumentPath error:nil];

    }

VAssetExportSession *exporter = [[[AVAssetExportSessionalloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality] autorelease];

 

exporter.outputURL=url;

   exporter.outputFileType = @"com.apple.quicktime-movie";

    exporter.shouldOptimizeForNetworkUse = YES;

    [exporter exportAsynchronouslyWithCompletionHandler:^{

         switch ([exporter status]) {

             caseAVAssetExportSessionStatusFailed:

                 break;

             caseAVAssetExportSessionStatusCancelled:

                 break;

             caseAVAssetExportSessionStatusCompleted:

                break;

            default:

                break;

        }

     }];

 }

 // The import will be completed only when control reaches to  Handler block
 
 

- (NSString*) applicationDocumentsDirectory

{

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString* basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

    return basePath;

}


      
Posted by k_ben


http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework



I'd like to introduce a new open source framework that I've written, called GPUImage. The GPUImage framework is a BSD-licensed iOS library (for which the source code can be found on Github) that lets you apply GPU-accelerated filters and other effects to images, live camera video, and movies. In comparison to Core Image (part of iOS 5.0), GPUImage allows you to write your own custom filters, supports deployment to iOS 4.0, and has a slightly simpler interface. However, it currently lacks some of the more advanced features of Core Image, such as facial detection.

UPDATE (4/15/2012): I've disabled comments, because they were getting out of hand. If you wish to report an issue with the project, or request a feature addition, go to its GitHub page. If you want to ask a question about it, contact me at the email address in the footer of this page, or post in the new forum I have set up for the project.

About a year and a half ago, I gave a talk at SecondConf where I demonstrated the use of OpenGL ES 2.0 shaders to process live video. The subsequent writeup and sample code that came out of that proved to be fairly popular, and I've heard from a number of people who have incorporated that video processing code into their iOS applications. However, the amount of code around the OpenGL ES 2.0 portions of that example made it difficult to customize and reuse. Since much of this code was just scaffolding for interacting with OpenGL ES, it could stand to be encapsulated in an easier to use interface.

Example of four types of video filters

Since then, Apple has ported some of their Core Image framework from the Mac to iOS. Core Image provides an interface for doing filtering of images and video on the GPU. Unfortunately, the current implementation on iOS has some limitations. The largest of these is the fact that you can't write your own custom filters based on their kernel language, like you can on the Mac. This severely restricts what you can do with the framework. Other downsides include a somewhat more complex interface and a lack of iOS 4.0 support. Others have complained about some performance overhead, but I've not benchmarked this myself.

Because of the lack of custom filters in Core Image, I decided to convert my video filtering example into a simple Objective-C image and video processing framework. The key feature of this framework is its support for completely customizable filters that you write using the OpenGL Shading Language. It also has a straightforward interface (which you can see some examples of below) and support for iOS 4.0 as a target.

Note that this framework is built around OpenGL ES 2.0, so it will only work on devices that support this API. This means that this framework will not work on the original iPhone, iPhone 3G, and 1st and 2nd generation iPod touches. All other iOS devices are supported.

The following is my first pass of documentation for this framework, an up-to-date version of which can be found within the framework repository on GitHub:

General architecture

GPUImage uses OpenGL ES 2.0 shaders to perform image and video manipulation much faster than could be done in CPU-bound routines. It hides the complexity of interacting with the OpenGL ES API in a simplified Objective-C interface. This interface lets you define input sources for images and video, attach filters in a chain, and send the resulting processed image or video to the screen, to a UIImage, or to a movie on disk.

Images or frames of video are uploaded from source objects, which are subclasses of GPUImageOutput. These include GPUImageVideoCamera (for live video from an iOS camera) and GPUImagePicture (for still images). Source objects upload still image frames to OpenGL ES as textures, then hand those textures off to the next objects in the processing chain.

Filters and other subsequent elements in the chain conform to the GPUImageInput protocol, which lets them take in the supplied or processed texture from the previous link in the chain and do something with it. Objects one step further down the chain are considered targets, and processing can be branched by adding multiple targets to a single output or filter.

For example, an application that takes in live video from the camera, converts that video to a sepia tone, then displays the video onscreen would set up a chain looking something like the following:

GPUImageVideoCamera -> GPUImageSepiaFilter -> GPUImageView

A small number of filters are built in:

  • GPUImageBrightnessFilter
  • GPUImageContrastFilter
  • GPUImageSaturationFilter
  • GPUImageGammaFilter
  • GPUImageColorMatrixFilter
  • GPUImageColorInvertFilter
  • GPUImageSepiaFilter: Simple sepia tone filter
  • GPUImageDissolveBlendFilter
  • GPUImageMultiplyBlendFilter
  • GPUImageOverlayBlendFilter
  • GPUImageDarkenBlendFilter
  • GPUImageLightenBlendFilter
  • GPUImageRotationFilter: This lets you rotate an image left or right by 90 degrees, or flip it horizontally or vertically
  • GPUImagePixellateFilter: Applies a pixellation effect on an image or video, with the fractionalWidthOfAPixel property controlling how large the pixels are, as a fraction of the width and height of the image
  • GPUImageSobelEdgeDetectionFilter: Performs edge detection, based on a Sobel 3x3 convolution
  • GPUImageSketchFilter: Converts video to a sketch, and is the inverse of the edge detection filter
  • GPUImageToonFilter
  • GPUImageSwirlFilter
  • GPUImageVignetteFilter
  • GPUImageKuwaharaFilter: Converts the video to an oil painting, but is very slow right now

but you can easily write your own custom filters using the C-like OpenGL Shading Language, as described below.

Adding the framework to your iOS project

Once you have the latest source code for the framework, it's fairly straightforward to add it to your application. Start by dragging the GPUImage.xcodeproj file into your application's Xcode project to embed the framework in your project. Next, go to your application's target and add GPUImage as a Target Dependency. Finally, you'll want to drag the libGPUImage.a library from the GPUImage framework's Products folder to the Link Binary With Libraries build phase in your application's target.

GPUImage needs a few other frameworks to be linked into your application, so you'll need to add the following as linked libraries in your application target:

  • CoreMedia
  • CoreVideo
  • OpenGLES
  • AVFoundation
  • QuartzCore

You'll also need to find the framework headers, so within your project's build settings set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the GPUImage source directory. Make this header search path recursive.

To use the GPUImage classes within your application, simply include the core framework header using the following:

#import "GPUImage.h"

As a note: if you run into the error "Unknown class GPUImageView in Interface Builder" or the like when trying to build an interface with Interface Builder, you may need to add -ObjC to your Other Linker Flags in your project's build settings.

Performing common tasks

Filtering live video

To filter live video from an iOS device's camera, you can use code like the following:

GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"CustomShader"];
GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, viewWidth, viewHeight)];
 
// Add the view somewhere so it's visible
 
[videoCamera addTarget:thresholdFilter];
[customFilter addTarget:filteredVideoView];
 
[videoCamera startCameraCapture];

This sets up a video source coming from the iOS device's back-facing camera, using a preset that tries to capture at 640x480. A custom filter, using code from the file CustomShader.fsh, is then set as the target for the video frames from the camera. These filtered video frames are finally displayed onscreen with the help of a UIView subclass that can present the filtered OpenGL ES texture that results from this pipeline.

Processing a still image

There are a couple of ways to process a still image and create a result. The first way you can do this is by creating a still image source object and manually creating a filter chain:

UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];
 
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
 
[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];
 
UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];

For single filters that you wish to apply to an image, you can simply do the following:

GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];

Writing a custom filter

One significant advantage of this framework over Core Image on iOS (as of iOS 5.0) is the ability to write your own custom image and video processing filters. These filters are supplied as OpenGL ES 2.0 fragment shaders, written in the C-like OpenGL Shading Language.

A custom filter is initialized with code like

GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"CustomShader"];

where the extension used for the fragment shader is .fsh. Additionally, you can use the -initWithFragmentShaderFromString: initializer to provide the fragment shader as a string, if you would not like to ship your fragment shaders in your application bundle.

Fragment shaders perform their calculations for each pixel to be rendered at that filter stage. They do this using the OpenGL Shading Language (GLSL), a C-like language with additions specific to 2-D and 3-D graphics. An example of a fragment shader is the following sepia-tone filter:

varying highp vec2 textureCoordinate;
 
uniform sampler2D inputImageTexture;
 
void main()
{
    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    lowp vec4 outputColor;
    outputColor.r = (textureColor.r * 0.393) + (textureColor.g * 0.769) + (textureColor.b * 0.189);
    outputColor.g = (textureColor.r * 0.349) + (textureColor.g * 0.686) + (textureColor.b * 0.168);    
    outputColor.b = (textureColor.r * 0.272) + (textureColor.g * 0.534) + (textureColor.b * 0.131);
 
	gl_FragColor = outputColor;
}

For an image filter to be usable within the GPUImage framework, the first two lines that take in the textureCoordinate varying (for the current coordinate within the texture, normalized to 1.0) and the inputImageTexture varying (for the actual input image frame texture) are required.

The remainder of the shader grabs the color of the pixel at this location in the passed-in texture, manipulates it in such a way as to produce a sepia tone, and writes that pixel color out to be used in the next stage of the processing pipeline.

One thing to note when adding fragment shaders to your Xcode project is that Xcode thinks they are source code files. To work around this, you'll need to manually move your shader from the Compile Sources build phase to the Copy Bundle Resources one in order to get the shader to be included in your application bundle.

Filtering and re-encoding a movie

Movies can be loaded into the framework via the GPUImageMovie class, filtered, and then written out using a GPUImageMovieWriter. GPUImageMovieWriter is also fast enough to record video in realtime from an iPhone 4's camera at 640x480, so a direct filtered video source can be fed into it.

The following is an example of how you would load a sample movie, pass it through a pixellation and rotation filter, then record the result to disk as a 480 x 640 h.264 movie:

movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
pixellateFilter = [[GPUImagePixellateFilter alloc] init];
GPUImageRotationFilter *rotationFilter = [[GPUImageRotationFilter alloc] initWithRotation:kGPUImageRotateRight];
 
[movieFile addTarget:rotationFilter];
[rotationFilter addTarget:pixellateFilter];
 
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
 
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
[pixellateFilter addTarget:movieWriter];
 
[movieWriter startRecording];
[movieFile startProcessing];

Once recording is finished, you need to remove the movie recorder from the filter chain and close off the recording using code like the following:

[pixellateFilter removeTarget:movieWriter];
[movieWriter finishRecording];

A movie won't be usable until it has been finished off, so if this is interrupted before this point, the recording will be lost.

Sample applications

Several sample applications are bundled with the framework source. Most are compatible with both iPhone and iPad-class devices. They attempt to show off various aspects of the framework and should be used as the best examples of the API while the framework is under development. These include:

ColorObjectTracking

A version of my ColorTracking example ported across to use GPUImage, this application uses color in a scene to track objects from a live camera feed. The four views you can switch between include the raw camera feed, the camera feed with pixels matching the color threshold in white, the processed video where positions are encoded as colors within the pixels passing the threshold test, and finally the live video feed with a dot that tracks the selected color. Tapping the screen changes the color to track to match the color of the pixels under your finger. Tapping and dragging on the screen makes the color threshold more or less forgiving. This is most obvious on the second, color thresholding view.

SimpleImageFilter

A bundled JPEG image is loaded into the application at launch, a filter is applied to it, and the result rendered to the screen. Additionally, this sample shows two ways of taking in an image, filtering it, and saving it to disk.

MultiViewFilterExample

From a single camera feed, four views are populated with realtime filters applied to camera. One is just the straight camera video, one is a preprogrammed sepia tone, and two are custom filters based on shader programs.

FilterShowcase

This demonstrates every filter supplied with GPUImage.

BenchmarkSuite

This is used to test the performance of the overall framework by testing it against CPU-bound routines and Core Image. Benchmarks involving still images and video are run against all three, with results displayed in-application.

Things that need work

This is just a first release, and I'll keep working on this to add more functionality. I also welcome any and all help with enhancing this. Right off the bat, these are missing elements I can think of:

  • Images that exceed 2048 pixels wide or high currently can't be processed on devices older than the iPad 2 or iPhone 4S.
  • Currently, it's difficult to create a custom filter with additional attribute inputs and a modified vertex shader.
  • Many common filters aren't built into the framework yet.
  • Video capture and processing should be done on a background GCD serial queue.
  • I'm sure that there are many optimizations that can be made on the rendering pipeline.
  • The aspect ratio of the input video is not maintained, but stretched to fill the final image.
  • Errors in shader setup and other failures need to be explained better, and the framework needs to be more robust when encountering odd situations.

Hopefully, people will find this to be helpful in doing fast image and video processing within their iOS applications.

      
Posted by k_ben


http://daoudev.tistory.com/entry/모바일-기기에서의-동영상-재생#footnote_link_28_8



1. 지원 파일

 

 

안드로이드 공식 지원 파일 포맷

코덱

확장자

비고

H.263

3gp, mp4

 

H.264 AVC

3gp, mp4, ts

인코딩은 허니컴부터 지원

ts 형식 또한 허니컴부터 지원

MPEG-4 SP

3gp

 

VP8

webm, mkv

2.3.3 부터 지원

스트리밍 형태는 ICS 부터 가능

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

아이폰 공식 지원 파일 포맷

코덱

확장자

비고

H.264

m4v, mp4, mov, 3gp

640 * 480, 30fps, 1.5Mbps

320 * 240, 30fps, 768Kbps

MPEG-4

m4v, mp4, mov, 3gp

640 * 480, 30fps, 2.5Mbps

 

 

 

 

 

 

 

 

 

 

2. 모바일 동영상 재생 방법

 

동영상은 다운로드 또는 스트리밍 방식으로 재생할 수 있습니다.

안드로이드 기반의 모바일 기기에서는 RTSP(Realtime Streaming Protocol)/HLS(HTTP Live Streaming) 지원합니다. 단, HLS 안드로이드 3.0 이상의 OS부터 지원하고 있습니다. iOS기반의 아이폰은 HLS1 지원하며,이외의 방식은 reject 사유에 포함됩니다.

 

참고로 아이폰에서의 동영상 재생 심사 기준에 대해서 알려드리겠습니다.HLS를 사용하지 않고, 10Mb 이상의 파일을 스트리밍 형식으로 재생하는 경우 reject 사유에 포함됩니다.

 

- 인코딩시 비트레이트 조건

화질

비디오

오디오

Low

96Kbps

64Kbps

Medium

256Kbps

64Kbps

High

800Kbps

64Kbps

 

 

모바일에서 일반 동영상 파일을 재생 하기 위해서는 모바일 플랫폼별 지원 포맷으로 변환하는 과정이 필요합니다. (FFmpeg Open Source 에서 지원)

 

 

3. FFMpeg 소개

 

FFMpeg는 인코딩2/먹싱3/트랜스코딩/디먹싱4/디코딩5/스트림/재생 등 멀티미디어 관련한 거의 모든 기능을 갖추고 있는 오픈 소스 멀티 미디어 프레임워크입니다. 크로스 플랫폼(Cross Platform)을 지원하고 GNU Lesser General Public License (LGPL) 라이선스에 의해 배포됩니다.

FFMpeg는 간단한 동영상 출력 프로그램인 ffplay도 제공합니다.

 

FFMpeg Library

  • libavcodec: 오디오/비디오의 인코더/디코더

  • libavformat: 오디오/비디어 컨테이너 포맷의 muxer/demuxer
  • libavutil: FFmpeg 개발  필요한 다양한 유틸리티
  • libpostproc: video post-processing
  • libswscale: 비디오의 image scaling, color-space, pixel-format 변환
  • libavfilter: 인코더와 디코더 사이에서 오디오/비디오를 변경하고 검사
  • libswresample: 오디오 리샘플링(audio resampling)

 

일반적인 컨버팅 절차

 

FFMpeg 동영상 컨버팅 과정

 

 

출처: http://helloworld.naver.com/helloworld/8794

 

1) libavformat  통해 비디어코덱과 오디오 코덱의 정보를 추출

2) libavcodec  통해 비디오/오디오 데이터를 디코딩

3) PC, 모바일에서 동일하게 적용되는 방법이며 위에서 추출한 데이터를 기반으로 파일로 저장/재생/편집

 

 

동영상 플레이어 구현 방법

 

출처: http://helloworld.naver.com/helloworld/8794

 

1) 컨버팅 과정에서 받은 정보를 큐에 저장

2) 큐에 저장된 정보를 SDL6 통해서 지속적으로 렌더링하여 재생

 - 영상비디오 Refresher 프레임 갱신을 요청/처리하여 비디오 Renderer 통해서 화면에 출력

 - 오디오오디오 Renderer 통해 오디오 정보를 재생

 

 

4. 구현 방법 시나리오

 

A. 서버에서 변환하는 경우

 

A-1) 컨텐츠 제공자가 파일을 등록할  변환

 

- 파일이 업로드 되면 서버에서 자동으로 파일을 변환하여 저장하는 방식

- FFmpeg 에서 제공하는 변환 기능을 통해 업로드  파일을 변환 저장 가능

- 유튜브네이버네이트  동영상 스트리밍 서비스에서 주로 사용되는 방식

 

A-2) 컨텐츠 제공자가 파일 스트리밍 요청할 때 변환

 

스트리밍 요청이 왔을 때 서버에서 실시간으로 변환하며 스트리밍

- 네이버 N드라이브가 모바일에서 동영상 전송시 사용되는 방식

- 대다수의 RTSP, HLS 기능을 포함한 서버 툴이 이러한 방식을 사용

 

A-3) 컨텐츠 제공자가 규약된 포맷으로 변환 후 업로드

 

- 컨텐츠 제공자가 규약된 포맷으로 변환하여 서버에 업로드

- 개인 사용자가 사용 가능한 다양한 변환 툴7이 있음.

- 개인용 서버에서 주로 사용되는 방식


 

B. 모바일에서 변환하는 경우

 

B-1) 변환 후 내장 플레이어로 플레이 가능한 파일로 저장

 

- 전달받은 영상 정보를 파일로 변환하여 저장 후 재생하는 방식

- FFmpeg 에 내장된 기능으로 특정 포맷으로 파일 변환/저장이 가능

- 일반 듀얼코어 PC 에서 800M 영상을 변환시 12분 소요

- 이보다  성능이 낮은 모바일 기기에서 구현시 배터리와 성능에 있어서 많은 문제가 있을것으로 예상됨.

 

B-2) 변환 후 내장 플레이어로 데이터 전달

 

 

- 내장 플레이어에 접근 가능한 모듈을 통해 변환 정보를 전송하는 방식

- 모바일 내장 플레이어에 대한 플러그인이 공식적으로 지원되지 않음.

- 별도의 제조사별 협의가 필요하며 다양한 기기에 대한 지원 대책이 필요함.

 

B-3) 변환 기능이 포함된 플레이어를 통해 플레이

 

 

- 전달 받은 영상 정보를 변환 모듈을 추가한 플레이어를 통해 재생하는 방식

- 가장 일반적인 방법으로 FFmpeg 를 활용한 다양한 플레이어가 있음.

- NHN 의 N드라이브 내장 플레이어 (안드로이드, iOS), AVPlayer (iOS) 가 개발 소스를 공개함.8

 

  1. HTTP Live Streaming 애플에서 2009년 iOS 3.0 발표 때 내놓은 프로토콜로 스트리밍 데이터를 MPEG-2 TS에 담아 시간단위로 쪼개서 보냅니다. Adobe사는 Flash Media Server 4.0에서, MicroSoft에서는 IIS Media Server 4.0 에서부터 정식 지원했으며 안드로이드는 3.0에서부터 지원합니다. [본문으로]
  2. 인코딩 (Encoding): 영상 데이터를 특정 동영상 코덱으로 변환하는 것 [본문으로]
  3. 먹싱 (Muxing): 변환한 데이터를 Digital Container Format 파일에 담는 것 [본문으로]
  4. 디먹싱 (Demuxing): 먹싱과 반대 개념으로 동영상 파일로 부터 비트 스트림 데이터를 추출하는 것 [본문으로]
  5. 디코딩 (Decoding): 특정 코덱의 데이터로부터 영상 데이터를 추출하는 것 [본문으로]
  6. SDL(Simple Directmedia Layer) : 비디오, 오디오, 사용자 입력 등의 계층을 추상화하여, 리눅스, 마이크로소프트 윈도, 맥 OS X 등 여러 운영 체제에서 실행이 가능하도록 한 크로스플랫폼 멀티미디어 라이브러리 [본문으로]
  7. 이러한 프로그램을 인코더(Encoder)라고 부른다. 특정 포맷의 동영상을 다른 포맷의 영상파일로 바꿔주는 기능을 수행한다. 국내에서 대중적으로 사용되는 프로그램은 다음의 팟 인코더이며 FFmpeg 를 활용하여 개발되었다. 라이센스는 개인/기업/공공/교육 등에 제한이 없다. [본문으로]
  8. 안드로이드 소스: http://helloworld.naver.com/helloworld/8794, N드라이브에 내장된 플레이어의 개발 과정 및 샘플 프로젝트가 공개됨. iOS 소스: http://luuvish.org/206, 엔터테이먼트 부문 2위 ( 플레이어 1위) 인 AVPlayer 소스가 공개됨. [본문으로]
------------------------------------------------------------------------------

플랫폼별 기본 내장 브라우저에서 플레이 가능한 코덱

 

코덱

iPhone

iPad

Android

H.263[i]

X

O

O

H.264[ii]

O

O

O

MPEG-4 Part2[iii]

O

O

O

VP8[iv]

X

X

O

 

 

 

 

 

 

 


  • iOS 브라우저 특징 - iOS 4.2 이상의 iPad 에서는 내장 브라우저 내에 비디오 컨트롤러가 포함되어 있으며, iPhone에서는 비디오 플레이어를 별도로 실행하여 플레이한다.
  • 안드로이드 브라우저 특징 - HTML 태그에 따라 브라우저 내 재생과 플레이어 호출이 각각 이루어 진다.

 

[i] H.263: H.261 코덱 기반으로 개발되었다. H.261에 비해 절반의 대역폭으로 똑같은 화질을 얻을 수 있기 때문에H.261을 대신해 범용으로 사용되며 비디오 스트리밍 전송을 위한 실시간 전송 프로토콜(RTP)에 사용되고 있다.

[ii] H.264/ MPEG-4 AVC: 매우 높은 데이터 압축률을 가지는 디지털 비디오 코덱 표준으로 MPEG-4 파트 10 또는MPEG-4/AVC(고급 비디오 부호화, Advanced Video Coding)라 부르기도 한다.

[iii] MPEG-4 Part 2 / SP: MPEG-4 Part2 또는 MPEG-4 Visual 또는 MPEG-4 ASP은 ISO/IEC의 동화상 전문가 그룹(MPEG)에서 만든 디지털 비디오 코덱이다. DivX, Xvid 등이 이 코덱의 구현에 해당한다.

[iv] VP8: 구글이 인수한 On2 테크놀로지스의 비디오 코덱 중 하나이다. BSD 라이선스 형식의 특허 대응을 위해, 수정 라이선스로 오픈 소스 소프트웨어화 함.

 

 

 

모바일 브라우저에서 동영상 플레이 하는 방법

 

브라우저 내에서 플레이

1
2
3
4
5
6
7
8
9
10
11
12
<video id="player1" width="600" height="360" controls>
    <source src="./h264.mp4" />
</video>
 
 
// 터치시 플레이가 되도록 스크립트 구성
<script language="javascript">
    var player1 = document.getElementById('player1');<br>
    player1.addEventListener('click', function() {
    player1.play();
    }, false);
</scipt>



미디어 플레이어 호출을 통한 플레이


 

테스트 결과

1) iOS 테스트

플랫폼

테스트

H.264

H.263

MPEG-4 PART 2

비고

재생/호출

재생/호출

재생/호출

iPhone

유튜브

O

X

O

Quick Player 호출 후 재생

iPad

O

O

O

Safari 내에서 재생

2) 안드로이드 테스트

브라우저

테스트

H.264

H.263

MPEG-4

PART 2

비고

재생

호출

재생

호출

재생

호출

기본

유튜브

 

O

O

O

O

O

O

호출 시

다운로드 선택 가능

Chrome

O

O

O

O

O

O

-

Firefox

X

X

X

호출 시

다운로드만 지원함

Dolphin

O

O

O

O

O

O

호출 시

다운로드 선택 가능

Boat

X

O

O

O

O

O

Maxthon

O

O

O

O

O

O

Xscope

O

O

O

O

O

O



      
Posted by k_ben


http://www.iphones.ru/forum/index.php?showtopic=77707

testImageArray = [[[NSArray alloc] initWithObjects:
                                                                       
[UIImage imageNamed:@"1.png"],
                                                                       
[UIImage imageNamed:@"2.png"],
                                                                       
[UIImage imageNamed:@"3.png"],
                                                                       
[UIImage imageNamed:@"4.png"],
                                                                       
[UIImage imageNamed:@"5.png"],
                                                                 
nil]autorelease];

                       
[self writeImageAsMovie:testImageArray toPath:documentsDirectory size:CGSizeMake(460, 320) duration:1];


-(void)writeImageAsMovie:(NSArray *)array toPath:(NSString*)path size:(CGSize)size duration:(int)duration 
{
       
NSError *error = nil;
       
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:
                                                                 
[NSURL fileURLWithPath:path] fileType:AVFileTypeQuickTimeMovie
                                                                                                                          error
:&error];
       
NSParameterAssert(videoWriter);
       
       
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                                                   
AVVideoCodecH264, AVVideoCodecKey,
                                                                   
[NSNumber numberWithInt:size.width], AVVideoWidthKey,
                                                                   
[NSNumber numberWithInt:size.height], AVVideoHeightKey,
                                                                   
nil];
       
AVAssetWriterInput* writerInput = [[AVAssetWriterInput
                                                                                assetWriterInputWithMediaType
:AVMediaTypeVideo
                                                                                outputSettings
:videoSettings] retain];
       
       
AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
                                                                                                         assetWriterInputPixelBufferAdaptorWithAssetWriterInput
:writerInput
                                                                                                         sourcePixelBufferAttributes
:nil];
       
NSParameterAssert(writerInput);
       
NSParameterAssert([videoWriter canAddInput:writerInput]);
       
[videoWriter addInput:writerInput];
       
       
       
//Start a session:
       
[videoWriter startWriting];
       
[videoWriter startSessionAtSourceTime:kCMTimeZero];
       
       
CVPixelBufferRef buffer = NULL;
       
//buffer = [self pixelBufferFromCGImage:[[array objectAtIndex:0] CGImage]];
        buffer
= [self pixelBufferFromCGImage:[[array objectAtIndex:0] CGImage] size:CGSizeMake(460, 320)];
       
CVPixelBufferPoolCreatePixelBuffer (NULL, adaptor.pixelBufferPool, &buffer);
       
       
[adaptor appendPixelBuffer:buffer withPresentationTime:kCMTimeZero];
       
int i = 1;
       
while (writerInput.readyForMoreMediaData)
       
{
               
NSLog(@"inside for loop %d",i);
               
CMTime frameTime = CMTimeMake(1, 20);
               
               
CMTime lastTime=CMTimeMake(i, 20); //i is from 0 to 19 of the loop above
               
               
CMTime presentTime=CMTimeAdd(lastTime, frameTime);
               
               
if (i >= [array count])
               
{
                        buffer
= NULL;
               
}
               
else
               
{
                        buffer
= [self pixelBufferFromCGImage:[[array objectAtIndex:0] CGImage] size:CGSizeMake(460, 320)];
               
}                
               
//CVBufferRetain(buffer);
               
               
if (buffer)
               
{
                       
// append buffer
                       
[adaptor appendPixelBuffer:buffer withPresentationTime:presentTime];
                        i
++;
               
}
               
else
               
{
                       
// done!
                       
                       
//Finish the session:
                       
[writerInput markAsFinished];
                       
[videoWriter finishWriting];                            
                       
                       
CVPixelBufferPoolRelease(adaptor.pixelBufferPool);
                       
[videoWriter release];
                       
[writerInput release];
                       
NSLog (@"Done");
//                      [imageArray removeAllObjects];                    
                       
break;
               
}
       
}
       
        path
= [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/myMovie.m4v"]];
       
//UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
       
       
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
       
NSParameterAssert(library);
       
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[NSURL fileURLWithPath:path]]) {
               
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError *error){}];   //Тут ошибка вылетает
       
}
       
[library release];
}


      
Posted by k_ben