본문 바로가기

ios 뽀개기/objective-c76

ios push 갱신 https://captainwonjong.github.io/2018-10-22/APNS-%EC%9D%B8%EC%A6%9D%EC%84%9C-%EB%B0%9C%EA%B8%89,-%EA%B0%B1%EC%8B%A0/ http://throughkim.kr/2016/12/27/ios-notification/ http://devstory.ibksplatform.com/2017/09/ios-3-apn.html https://nicgoon.tistory.com/203 2020. 4. 14.
NSNotification 예제 (자식창 닫을때 부모창도 같이 닫기) NSNotification 예제 최상위뷰가 있다. 최상위 뷰에서 부모뷰를 띄웠다. 부모뷰에서 자식 뷰를 띄웠다. 이때, 자식뷰를 닫을때 부모뷰까지 같이 닫아 줘야하는 요구사항이 있다. 이럴때는 NSNotification 을 사용한다. 먼저 부모뷰에 NSNotification 설정과 콜백메소드(편의상 이렇게 부르겠다)를 작성해준다. viewdidload{ //노티피케이션 등록 - 자식창을 닫을때 이곳(부모)도 닫히게 노티 등록 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeViewControllerBySelf:) name:@"close" object:nil]; } 이렇게 셋팅을 해주고 호출될 메소드를 작성해준다... 2019. 10. 24.
NSTimer & label 속성 (가운데, 줄간격, 위치고정 등) 30초 카운트 다운 타이머 만들기 (countdownlabel 객체는 storybord에 미리 만들어 놓는다.) #import @interface SosRequestViewController : UIViewController //타이머 객체 @property(strong,nonatomic) NSTimer *CountDownTimer; @property (nonatomic, assign) NSInteger second; @end .m //타이머 시작! -(void)startTimer{ //폰트를 넣어줘야, lable 위치가 흔들리지 않는다. UIFont *myfont = [UIFont monospacedDigitSystemFontOfSize:_countDownLabel.font.pointSize weigh.. 2019. 10. 24.
단순 팝업 메시지 //단순 메시지 전달해서 팝업 띄우기 메소드 - (void)popUpWithMessage:(NSString *)message { UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"알림" message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [alert dismissViewControllerAnimated:YES completion:nil]; }]; [.. 2019. 10. 24.
ios 인디케이터 .h //인디케이터 객체 선언 @property (nonatomic, retain) UIActivityIndicatorView *activityIndicator; .m //인디케이터 시작 -(void)startIndicater{ NSLog(@"인디케이터 시작"); // ProgressBar Setting _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; [_activityIndicator setCenter:self.view.center]; [_activityIndicator setColor:UIColor.whiteColor]; if (@available(iOS 13.0, *)) { [_.. 2019. 10. 24.
ios 디바이스 사이즈 구하기 & xib 파일 이름으로 뷰 띄우기 //디바이스 사이즈 구하기 CGRect screenRect=[[UIScreen mainScreen]bounds]; CGFloat deviceWidth=screenRect.size.width; CGFloat deviceHeight=screenRect.size.height; //xib 파일 이름으로 뷰컨트롤러 객체 생성 _cancelViewController=[[CancelViewController alloc]initWithNibName:@"CancelViewController" bundle:nil]; //상단에 얻은 디바이스 크기로 뷰를 호출하기전에 리사이즈 합니다. [_cancelViewController.view setFrame:CGRectMake(0, 0, deviceWidth, deviceHeigh.. 2019. 10. 24.
viewDidLoad 에서 alert 띄울때 발생하는 오류 viewDidLoad 에서 alertViewController를 띄우면 계층구조 오류 메시지를 던지고 alert가 뜨지 않는다. 처음에는, 뷰가 로드 되었는데 왜 안떠? 라고 생각하고 구글에서 삽질을 좀 했다. 알고봤더니 뷰가 로드는 되었지만 나타나지는 않았기 때문에 viewDidLoad에서 alert 를 띄우면 alert를 띄울수 있는 부모 viewcontroller가 없다고 난 에러였다. 그래서 viewController에서 alert를 띄울려면 viewDidLoad 말고viewDidAppear 이나 다른 메소드를 만들어서 alert를 띄어줘야 한다. 2019. 10. 23.
문자 타입의 바이트를 NSData타입으로 변환 문자 타입의 바이트를 NSData타입으로 변환 #import NS_ASSUME_NONNULL_BEGIN @interface Util : NSObject // 문자 타입의 바이트를 NSData타입으로 변환 +(NSMutableData *)convertStringToNSData:(NSString *) bytesString; @end NS_ASSUME_NONNULL_END #import "Util.h" @implementation Util // 문자 타입의 바이트를 NSData타입으로 변환 +(NSMutableData *)convertStringToNSData:(NSString *) bytesString{ //넘어온 문자형식의 byte NSString *signNum = bytesString; signNum .. 2019. 10. 22.
CALayer 관련 참고 페이지 //쿼츠코어를 임포트해야 CALayer 와 CoreAnimation을 사용할 수 있다. #import #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // #.정의 : CALayer는 스크린에 시각적 큰텐츠를 그리는 사각형의 class 이다. //self.view 는 viewcontroller 의 view 이다 . 이를통해 컨트롤러의 view 에 접근할 수 있다. //여기서 자동생성된 layer는 calayer이다. //배경.. 2019. 10. 18.
ios 로컬 음악파일 간단하게 재생하기 .h 파일 #import //사운드를 재생할 오디오 플레이어객체 , @property (nonatomic,strong)AVAudioPlayer *player; .m 파일 /* 로컬에 sound 파일 재생하기 위한 경로를 가져온다. 경로를 url 타입으로 변환 - > avaudioplayer로 재생. */ NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sos" ofType:@"wav"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; NSLog(@"soundFileURL : %@" , soundFileURL); NSError *error; self.player = [[AV.. 2019. 10. 18.
objective c 블루투스 corebluetooth objective c 블루투스 corebluetooth #import "SosRequestViewController.h" #import //코어 블루투스 라이브러리 추가한것 임포트 한다. #import //센트럴의 이벤트를 수행할 수 있도록, 델리게이트 구현 @interface ViewController : UIViewController @property (strong, nonatomic) CBCentralManager *centralManager; //센트럴 역할을 수행해줄 객체 @property (strong, nonatomic) CBPeripheral *safetyPeripheral; //주변기기 객체 @property (strong, nonatomic) CBCharacteristic *charac.. 2019. 10. 18.
protocol 개념 - 1 objective c 에서 프로토콜이라는 문법이 있다. 프로토콜은 약속,규칙이라는 뜻이다. 예를들어, Car Class 에 '작동' 이라는 프로토콜(약속)이 존재 한다면, 이 약속을 airplain, bike 등 여러 클래스에서 가져다가 사용할 수 있다. 조금 어렵게 말하면 프로토콜은 인터페이스(선언부) 이고, delegate 는 인터페이스를 구현하는 객체이다. 그럼 프로토콜을 쓰면 좋은점은 무엇일까? 바로 객체간 종속성이 줄어든다! //프로토콜 선언! @protocol ProtocolName @optional //구현해도 되고 안해도 되는 메소드 @required //필수적으로 구현해야 하는 메소드 @end //프로토콜 구현! @interface ClassName : 부모클래스 or @interface.. 2019. 10. 9.
AVCaptureVideoDataOutput을 이용해서 카메라 만들기 3 - 녹화 AVCaptureVideoDataOutput을 이용해서 카메라 만들기 3 - 녹화 로직 작성 순서는 아래와 같다 //녹화 step1 //IDCaptureSessionPipelineViewController클래스 - 녹화,정지 토글 버튼 기능 - (IBAction)toggleRecording:(id)sender { NSLog(@"IDCaptureSessionPipelineViewController - toggleRecording 버튼"); if (_recording) { [_captureSessionCoordinator stopRecording]; } else { //잠자기 모드 비활성화 [UIApplication sharedApplication].idleTimerDisabled = YES; //아직 세션.. 2019. 4. 17.
AVCaptureVideoDataOutput을 이용해서 카메라 만들기 2 - 녹화 AVCaptureVideoDataOutput을 이용해서 카메라 만들기 2 - 녹화 #.지난번 포스팅에 이어서 '녹화' 버튼을 클릭했을때 작동되는 로직 순서를 알아보자. 1.녹화버튼을 클릭 하면 IDCaptureSessionPipelineViewController클래스의 toggleRecording 메소드가 작동된다. 2.IDCaptureSessionAssetWriterCoordinator 클래스의 startRecording 진입해서 레코딩 상태변화를 시키기위해 transitionToRecordingStatus 메소드를 호출한다. // oldStatus : 0, newStatus: 1 3.IDCaptureSessionAssetWriterCoordinator 클래스의 startRecording 에서 계속해서.. 2019. 4. 17.
AVCaptureVideoDataOutput을 이용해서 카메라 만들기1 AVCaptureVideoDataOutput을 이용해서 카메라 만들기1 iOS 비디오 녹화 어플을 만들다가 생각지도 못한 난관에 봉착했다. 비디오를 녹화하는 도중에 녹화한 데이터크기를 실시간으로 체크하는 기능을 추가해야하는 상황이 발생했다. 젠장… AVCaptureMovieFileOutput을 이용해서 비디오를 커스터마이징 하고 있었는데, AVCaptureMovieFileOutput으로는 실시간으로 데이터를 체크가 불가능했다. 대신, AVCaptureVideoDataOutput 과 AVAssetWriter를 이용해야지 데이터 체크가 가능했다. 그리고 AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDeleg.. 2019. 4. 16.
Ios autoLayout 기초 Ios autoLayout 기초 예제소스 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //크기 고정 뷰 - 화면 정중앙에 배치될 정사각형의 뷰 만들기 UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; oneView.translatesAutoresizingMaskIntoConstraints = NO; //필수! [oneView setBackgroundColor:[UIColor brownColor]]; [self.view add.. 2019. 4. 5.
ios 화면보호기 & 터치 감지하기 ios 화면보호기 & 터치 감지하기 목표 iOS UIWindow에서 터치를 감지한 후 일정시간 터치가 없으면 화면보호기 viewcontroller 띄워주는 기능 구현 순서 *공통상수클래스 제작- CommonValues 설명: 화면보호기 시간을 설정해준다. #import @interface CommonValues : NSObject @property(nonatomic,assign) int SAVER_TIME; //화면보호기 시간 @end #import "CommonValues.h" @implementation CommonValues @synthesize SAVER_TIME; - (instancetype)init { self = [super init]; if (self) { SAVER_TIME = 3; //.. 2019. 4. 5.
날짜를 이용해서 파일 삭제하기 날짜를 이용해서 파일 삭제하기 날짜를 이용해서 30일이 지난 폴더 또는 파일을 삭제하는 기능을 구현해 보자. 먼저, 다큐먼트 폴더 안에 video, photo, audio 폴더가 각각있다고 가정하자. 위의 미디어 폴더 아래는 20190401, 20190402 와 같이 폴더 or 파일이름이 생성한 날짜인 파일들이 존재할 것이다. 참고로 다큐먼트 폴더는 사용자가 접근할 수 있는 최상위 폴더이다. 다큐먼트 이외의 폴더로는 애플 정책상(보안문제)접근이 어렵다. 필요한 데이터는 아래와 같다. 1.오늘날짜를 초를 변환한 값. 2.파일을 생성한 날짜를 초로 변환한 값 3.생성한 날짜에 30일(초값)을 더한 값. - 삭제예정일 (생성한 날짜를 초로 변환하고 30일을 초로 변환해서 계산 후 리턴 한다.) 위의 데이터를 .. 2019. 4. 3.
날짜계산(특정시간 이후 날짜 구하기) 날짜계산(특정시간 이후 날짜 구하기) 날짜와 시간을 위한 프로그래밍을 위해서는 기본적으로 NSDate를 사용한다. NSDate는 2001년 1월 1일 자정을 기준으로 현재시간(특정)까지의 경과한 시간(초)을 저장하고 있는 객체이다. 두 시점의 과거 , 미래 시간을 비교하는 작업은 가능하나, 구체적인 날짜나 요일을 구하기는 어렵다. (예 3월1일은 무슨요일인가 ?등) 날짜를 자유자재로 다룰려면 NSCalendar와 NSDateComponents 객체에 대해서 알아야 한다. NSDateComponents는 몇 월, 몇 일 등 날짜 정보를 구성하는 달력에서 기본 단위들에 대한 정보를 얻는데 사용된다. 실제로 NSDate 객체와 NSDateComponents 객체를 NSCalendar 객체가 연결해준다. *코드.. 2019. 4. 3.
uuid 구하기(ios 기기 고유번호) uuid 구하기(ios 기기 고유번호) 과거 iOS 기기의 고유 번호를 얻기 위해서 udid가 존재했었다. 하지만 개인정보 문제 등으로 ios5 부터는 udid가 사라지고 uuid(임의로 생성한 고유값)가 생겨났다. 애플도 uuid를 이용해서 기기 고유번호를 생성하라고 권고한다. 하지만 문제는 uuid도 앱을 삭제하면 새롭게 생성 된다. 즉 고유값이라고 할 수 없다. 개인정보 문제로 부터 자유로워졌긴 하지만, 개발자들이 이 고유번호를 다루기가 까다로워졌다. 여러 방법이 있겠지만 uuid를 최초로 생성하고 keychain에 저장시켜주는 방법 찾아보았다. /* File: KeychainItemWrapper.m Abstract: Objective-C wrapper for accessing a single ke.. 2019. 4. 2.
카메라 줌 AVCaptureDevice Zoom 카메라 줌 AVCaptureDevice Zoom 예전시간에 카메라 자동 회전 기능을 소개했다. https://abc1211.tistory.com/615 그곳에 카메라 줌기능을 넣기 위해서 이것저것 찾아보고 시도해보았다. 처음에는 카메라 캡쳐화면을 실시간으로 보여주는 PreviewLayer에 pinchegesture를 걸어서 제스쳐 변화 값을 이용해서 zoom해주면 된다고 생각했는데 거의 오전 내내 삽질을 했다. 결론은 previewlayer에는 gesture 를 걸 수 없다. Avcapturedevice 를 이용해야 한다. 아래는 해당 소스이다. 주석을 달아 놓았다. *제스쳐 함수 //self.view 에 pinches 제스쳐 이벤트를 걸었다. view 화면을 두 손가락으로 움직이면 AVCaptureDe.. 2019. 4. 2.
core audioqueue player 에 대하여 2(추가설명) core audioqueue player 에 대하여 2(추가설명) 지난번 글에서 오디오 큐로 오디오 플레이어를 구현하는 법을 포스팅 했다. 테스트를 하면서 확인해 본결과 오디오 파일을 읽을 때 읽을 패킷 값을 UInt32 numPackets = 10*1000; 이런식으로 고정값으로 해놓으니 런타임이 긴 오디오에서는 콜백을 타지 않는 현상이 발견했다. 그래서 DeriveBufferSize 함수를 만들어서 버퍼 사이즈와 한번에 읽을 패킷 수를 유동적으로 구하기로 했다. 또 지난번에 로그를 확인하는 시간을 안가졌다. 오디오 큐가 오디오 파일을 어떻게 읽는지, 그 읽은 값은 어떻게 되는지.또 오디오 파일을 읽은 후 오디오 큐가 콜백 함수를 어떻게 호출 하는지.. 콜백 함수 내부에서는 어떤일이 일어나는지 등등 로.. 2019. 3. 29.
core audioqueue player 에 대하여 core audioqueue player 에 대하여 코어오디오를 이용해서 음원을 플레이 하는 어플을 간단하게 만들어보았다. 애플 오디오 프로그래밍 가이드 문서를 기반으로 구현을 하였다. 작동 순서는 prepare 버튼을 눌러서 먼저 재생할 오디오 파일 형식, 파일 위치와 관련된 설정을 해준다. 그 후 start 버튼을 눌러서 음원을 재생한다. 재생을 하면 재생이 완료 될때까지 끊임없이 콜백함수가 호출되면서 오디오 파일에서 읽은 데이터를 버퍼에 넣고 출력한다. 그리고 음악이 종료되며면 dispose 버튼을 눌러서 메모리에 할당된 큐를 해제해준다. 처음에 이 프로세서를 알기까지 꽤 많은 시간이 걸렸다. 단순하게 오디오를 재생하려면 이미 만들어져있는 MediaPlayer 오디오 프레임워크를 가져다 쓰면된다. .. 2019. 3. 28.
core audio queue service (ios recording) core audio queue service 본글은 애플의 오디오큐서비스프로그래밍 가이드 문서를 참고해서 작성했습니다. 뷰 코드 //step 1. 라이브러리 임포트 #import #import #import #import #import //step1. 상태를 관리하기 위한 사용자정의 구조 static const int kNumberBuffers = 3; // 1 struct AQRecorderState { AudioStreamBasicDescription mDataFormat; // 2 . 오디오 데이터 포멧, mQueue에 사용된다. AudioQueueRef mQueue; // 3. 앱에 의해 생성되는 레코딩 오디오 큐 AudioQueueBufferRef mBuffers[kNumberBuffers]; .. 2019. 3. 26.
ios 카메라 화면 자동회전 (camera auto rotation) ios 카메라 화면 자동회전 (camera auto rotation) 코드 #import #import "ViewController.h" //화면 전체 가로, 세로길이 구하기#define kScreenWidth [UIScreen mainScreen].bounds.size.width#define kScreenHeight [UIScreen mainScreen].bounds.size.height //screen orientationbool g_isPortraitMode; //현재 세로냐 가로냐float _screenWidth_Landscape; // 가로일때 가로길이float _screenHeight_Landscape; //가로일때 세로길이float _screenWidth_Portrait; //세로일때 가로길.. 2019. 3. 8.
코어오디오 MediaPlayer 구현 MediaPlayer 구현 네비게이션 info.plist storyboard #import @interface ViewController : UIViewController @end //MediaPlayer 임포트!#import #import "ViewController.h" @interface ViewController () @property (strong,nonatomic) MPMediaPickerController *mpPickerVC; //픽커 컨트롤러@property (strong,nonatomic) MPMediaItemCollection *slctitems; //선택된 아이템@property (strong,nonatomic) MPMusicPlayerController *appMusicPlayer.. 2019. 3. 4.
엔터프라이즈 계정으로 배포 http://blog.saltfactory.net/distribute-ios-app-using-with-dropbox-without-server/ https://imhaba.tistory.com/41 복사한 링크 텍스트를 텍스트 에디터에 복붙 한다. 예 > https://www.dropbox.com/s/xbrrsqruajf27p0/apnsguide.ipa?dl=0 에디터를 통해서 www.dropbox.com 을 아래 텍스트로 치환하고 url 텍스트 끝의 ?dl=0 를 삭제한다. dl.dropboxusercontent.com 예> https://dl.dropboxusercontent.com/s/xbrrsqruajf27p0/apnsguide.ipa https://dl.dropboxusercontent.com.. 2019. 2. 15.
이미지 자르기 이미지 자르기 - (IBAction)CaptureAction:(id)sender { NSLog(@"캡쳐 버튼 눌렸습니다."); CGSize screenS = myImageView.frame.size; CGFloat delX = myImageView.image.size.width / screenS.width; CGFloat delY = myImageView.image.size.height / screenS.height; NSLog(@"myImageView.image.size.width : %f" ,myImageView.image.size.width ); NSLog(@"myImageView.image.size.height : %f" ,myImageView.image.size.height ); NSLog(@".. 2019. 1. 27.
UIpangesture로 UIView 옮기기& 특정 프레임 넘어가지 않게 설정 UIpangesture로 UIView 옮기기& 특정 프레임 넘어가지 않게 설정 소스 #import "ViewController.h" @interface ViewController (){ //사진틀 IBOutlet UIImageView *myImageView; //뷰파인더를 옮기기 전 위치 CGPoint beforPoint; //뷰파인더 UIView *viewFinder; //뷰파인더를 감싸고 있는 네 개의 점. UIView *leftTopPoint; UIView *rightTopPoint; UIView *leftDownPoint; UIView *rightDownPoint; UIBezierPath *blackPath; //검은색 블러 UIBezierPath *framePath; //포커스 CAShapeLa.. 2019. 1. 25.
일정시간이 지난 파일 자동 삭제하기 일정시간이 지난 파일 자동 삭제하기 앱실행할때 호출//일정 시간 지난 미디어 파일 지우기 [self deleteOverDateMediaFile]; //삭제 기준 날짜 가져오기 -(float)getDeleteStandardDateSeconds{ //기준이 되는 날짜 // 1. 3일 전 날짜를 구함 -> 데이터 포멧 변환 -> string으로 변환 -> 초 로변환 (568393200.000000) NSDateComponents* deltaComps = [[NSDateComponents alloc] init]; [deltaComps setDay: -3]; NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDa.. 2019. 1. 9.