반응형

iOS/Swift + Objective-c 80

[iOS] Push Notification (APNS) example

Push Notification (APNS) example 1. 앱에 푸시 추가 프로젝트 > TARGETS > Signing & Capabilities 에서 왼쪽 상단에 + Capability 선택 > Push Notifications 선택 > Background Modes 선택 > Remote notification 체크 2. 푸시 왔을 때 처리 코드 AppDelegate.h - UserNotifications import - UNUserNotificationCenterDelegate 추가 #import #import @interface AppDelegate : UIResponder AppDelegate.m - registerForRemoteNotifications PUSH 등록 - applicatio..

[iOS] 프레임워크 시뮬레이터 아키텍처 삭제 (platform doesn't have any non-simulator SDKs)

ios IPA 생성 시 아래와 같은 오류가 발생했다. IPA processing failed (해당 문제는 App Store Connect, Enterprise 시 발생하는듯?) 로그 파일로 자세히 보니 아래와 같은 오류가 있었다. Configuration issue: platform AppleTVSimulator.platform doesn't have any non-simulator SDKs; ignoring it Configuration issue: platform WatchSimulator.platform doesn't have any non-simulator SDKs; ignoring it Configuration issue: platform iPhoneSimulator.platform doesn..

[objective c] custom font 사용하기

[iOS: objective - c] framework & library 에서 custom font 사용하기 1. 커스텀 폰트를 프로젝트에 추가한다 2. info.plist 추가 3. -(void) addCustomFont { NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]]; NSString *fontPath = [frameworkBundle pathForResource:@"NanumMyeongjo" ofType:@"ttf"]; NSData *inData = [NSData dataWithContentsOfFile:fontPath]; CFErrorRef error; CGDataProviderRef provider = CGDataProv..

[iOS: objective - c] framework & library 에서 custom font 사용하기

[iOS: objective - c] framework & library 에서 custom font 사용하기 1. 커스텀 폰트를 프로젝트에 추가한다 2. info.plist 추가 3. -(void) addCustomFont { NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]]; NSString *fontPath = [frameworkBundle pathForResource:@"NanumMyeongjo" ofType:@"ttf"]; NSData *inData = [NSData dataWithContentsOfFile:fontPath]; CFErrorRef error; CGDataProviderRef provider = CGDataProv..

[iOS] status bar height 구하기 (상태바 높이 구하기)

[iOS] status bar height 구하기 (상태바 높이 구하기) 아이폰의 status bar 높이를 보통 20으로 처리하는데,해상도에 따라 다른 값을 가지고 있어서동적으로 값을 가져와서 처리하는 방법이 정확하다. 아래 코드로 상태바 높이를 가져올 수 있다. -(CGFloat)statusBarHeight { CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame]; return statusBarRect.size.height; }

[ios xcode] error: linker command failed with exit code 1

[ios xcode] error : linker command failed with exit code 1 Xcode 빌드 시 error: linker command failed with exit code 1 에러 초반엔 프레임워크 링크가 깨진건가 했는데, 에러 메시지 바로 위에 출력해주는 파일의 링크가 깨지는 원인이 대부분인것 같다. 경험상 그 파일을 검색해봤을 때 1. 없거나 2. 중복되서 있거나(두번 추가된 경우가 있음) 3. 프로젝트 파일 > Build Phases > Compile Sources에 추가가 안되어 있는 경우 – 파일이 Target에 추가 안된 것이 원인 이 세가지 케이스인것 같다. 비슷하게 실행은 잘 되는데 Unit Test 빌드가 깨질때도, Build Phases를 먼저 확인해보면..

[iOS Objective c] 화면 흔들기 (view shake) 구현

[iOS Objective c] 화면 흔들기 (view shake) 구현 setDuration : 애니메이션 실행 시간setRepeatCount : 애니메이션 실행 횟수 setFromValue : 애니메이션 시작 위치setToValue : 애니메이션 끝 위치 다음 코드는 0.05초 동안 좌우로 20.0f 씩 4번 흔드는 애니메이션 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation setDuration:0.05]; [animation setRepeatCount:4]; [animation setAutoreverses:YES]; [animation setFromValue:[NSValue val..

[iOS] NSMutableArray 배열 순서 섞기

[iOS] NSMutableArray 배열 순서 섞기 (랜덤으로 섞기) [Objective-c] for (int i=0; i < [arrTestA count]; i++) { int random = arc4random() % [arrTestA count]; [arrTestA exchangeObjectAtIndex:random withObjectAtIndex:i]; } 만약 특정 인덱스는 섞으면 안될 경우 아래 코드를 추가해주자. if (random == 5 || i == 5) { continue; } [Swift] extension Array { mutating func suffle() { if count < 2 { return } for i in 0 ..< (count - 1) { let j = Int(..

[Objective-c] @synthesize 사용 안해도 돼요

[Objective-c] @synthesize 사용 안해도 돼요! 가끔씩 맥이나 iOS 관련 개발 카페등을 보면, 2014년이 시작된 지금까지도 Objective C의 문법중 @synthesize에 관해 물어보는 분들이 계십니다. (참고로, Object C(오브젝트 C) 아닙니다. Objective C(오브젝티브 C) 입니다. 이거 헷갈리시는 분들이 있더군요.) 아마도, 조금 오래된 책으로 공부하거나(최근 책들은 보지 못했습니다만...) 예전에 작성되었던 소스들을 보면서 공부하기 때문인것 같습니다. 그런데, 사실 이제는 2012년 중반 이후로 Modern Objective C가 나온 이후 부터는 @synthesize는 더이상 사용할 일이 거의 없습니다. (정확히 버전은 기억나지 않지만 XCode 4.5정..

[ios] cocoapod 사용하기

[ios] cocoapod 사용하기 ios 개발할때 유용한 라이브러리들을 사용하는 방법중의 하나로 cocoapods를 꼽을 수 있다. 설치는 간단하다.sudo gem install cocoapods 제거 할때는 sudo gem uninstall cocoapods 설치한 이후 기존의 XCode 프로젝트 폴더에서 터미널에서 profile 생성 명령어를 실행해준다.pod init이렇게 하면 profile이 생성된다. 생성된 profile 파일을 텍스트 편집기에서 열어 추가 하고자 하는 라이브러리를 입력하고 저장해준다.(참고로 profile에서 #은 주석을 의미한다.)# platform :ios, '6.0'

[Objective-C] alloc, init 메서드

ClassA* a = [ClassA alloc]; alloc은 allocate(할당하다)의 줄임말이다. 새로운 클래스에 메모리 공간을 할당하는 것이다. 클래스에 alloc 메세지를 보내, 그 클래스의 새로운 인스턴스를 받는다. alloc 메서드는 객체의 모든 인스턴스 변수를 0으로 초기화한다. 그러나 이것으로 객체가 사용하기에 충분히 초기화되었다고 볼 수는 없다. 따라서 객체를 생성(allocate, 메모리에 할당)한 후, 초기화(initialize)해 주어야 한다. 이것은 다음 명령문으로 수행할 수 있다. a = [a init]; init 메서드는 클래스의 인스턴스를 초기화한다. a 변수에 init 메시지를 보내는 것에 주목하자. 이것은 클래스가 아니라 특정한 ClassA 객체를 초기화하는 것을 뜻한다..

[ios objective-c] 문자열 배열로 분리하기

문자열 배열로 분리1. NSString을 NSArray로 분리: componentsSeparatedByString: 사용NSString *myString = @"This is a test";NSArray *myWords = [myString componentsSeparatedByString:@" "]; // 이제 myWords는: [@"This", @"is", @"a", @"test"] 2. 여러 개의 토근을 사용할 경우: componentsSeparatedByCharactersInSet: 사용NSString *myString = @"Foo-bar/blee";NSArray *myWords = [myString componentsSeparatedByCharactersInSet:[NSCharacterSet ..

반응형