앱을 개발하다 보면 구현하고자 하는 기능에 따라서 위치정보를 이용해야 할 때가 있는데

iOS에서 위치정보를 사용하려고 하면 사용자의 동의를 먼저 받아야 한다.


먼저 프로젝트에 CoreLocation Framework를 추가한다.




이후에 해당 뷰 컨트롤러에서 위치정보 사용 동의를 받는 코드를 추가한다.

.h 헤더 파일
#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController @property (strong, nonatomic) CLLocationManager *locationManager;
.m 구현 파일
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [self.locationManager requestAlwaysAuthorization];
}
self.locationManager.pausesLocationUpdatesAutomatically = NO;


그리고 info.plist의 Custom iOS Target Properties에서 다음과 같이 설정해 준다.


위치정보 사용은 [사용 안함/앱을 사용할 때만/항상]  이렇게 3가지 형태가 있는데 필요한 기능에 따라서

requestAlwaysAuthorization 이나 requestWhenInUseAuthorization을 써주면 된다.

만약 항상 위치정보를 사용하지 않아도 되는데 requestAlwaysAuthorization을 사용한다면 심사 과정에서 리젝이 날 수도있으니 주의한다.

(경험 상 리뷰어한테도 충분히 설명을 해 줘야함)






'프로그래밍 > iOS - OBJC' 카테고리의 다른 글

iOS NSTimer 호출하기  (1) 2016.05.12
맥 OS X PhoneGap 설치  (0) 2016.04.27
iOS 8에서 푸시 알림 동의 받기  (0) 2016.03.10
Singleton 패턴 사용하기  (0) 2016.03.09
iOS 앱 자동로그인  (0) 2016.03.09

iOS 7->8 로 넘어오면서 푸시알림 동의 받는 코드가 바뀌었다.

개발 중인 앱은 최소 iOS 버전이 iOS 8버전 이상이지만 혹시나 구버전을 지원해야 하는 경우도 있기 때문에 함께 기록 해 본다.


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

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        NSLog(@"Requesting permission for push notifications...iOS 8"); // iOS 8
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
                                                UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound categories:nil];
        [UIApplication.sharedApplication registerUserNotificationSettings:settings];
    } else {
        NSLog(@"Registering device for push notifications...iOS 7 and earlier"); // iOS 7 and earlier
        [UIApplication.sharedApplication registerForRemoteNotificationTypes:
         UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeSound];
    }
}


그리고 아래는 디바이스가 APN 서버에 정상적으로 등록 되었는지 로그를 찍어서 확인 할 수 있는 코드

- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)settings
{
    NSLog(@"Registering device for push notifications...iOS 8"); // iOS 8
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
{
    NSLog(@"Registration successful, bundle identifier: %@, mode: %@, device token: %@",
          [NSBundle.mainBundle bundleIdentifier], [self modeString], token);
}

- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Failed to register: %@", error);
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler
{
    NSLog(@"Received push notification: %@, identifier: %@", notification, identifier); // iOS 8
    completionHandler();
}

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)notification
{
    NSLog(@"Received push notification: %@", notification); // iOS 7 and earlier
}

- (NSString *)modeString
{
#if DEBUG
    return @"Development (sandbox)";
#else
    return @"Production";
#endif
}



'프로그래밍 > iOS - OBJC' 카테고리의 다른 글

iOS NSTimer 호출하기  (1) 2016.05.12
맥 OS X PhoneGap 설치  (0) 2016.04.27
iOS에서 위치정보 사용 동의 받기  (0) 2016.03.10
Singleton 패턴 사용하기  (0) 2016.03.09
iOS 앱 자동로그인  (0) 2016.03.09

MDM 솔루션을 구축하기 위해서는 서버가 필요한데, LG U+ Cloud나 Naver NCloud Biz 등 에서

시스템 사양과 요금 등을 고려하여 적당한 시스템을 선택하면 된다.


MDM 서버는 SSL 적용이 필수인데 SSL 적용을 위한 인증서가 iOS에서 신뢰할 수 있는 인증기관(링크)에서 발급한 인증서를

써야 하는지 자가서명 된 인증서를 써도 되는지 모호하여 일단 자가서명 인증서를 사용하여 진행 해보기로 하였다.


ubuntu server는 설치되어 있는 상황이라고 가정하고 계속 진행을 해보자면 일단 맥의 터미널 프로그램을 이용하여 원격 서버에 접속한다.

먼저 터미널 실행 후 ssh root@ip주소  를 입력하여 우분투 서버에 접속을 한다.

초기 서버 셋팅 시 root 라는 유저 네임은 어떻게 설정하였는가에 따라 다르겠지만 보통 root를 많이 사용하므로 유저 네임은 root라고 본다.


먼저 APM (Apache, PHP, MySQL)을 설치한다.


apt-get update


apt-get install apache2


아파치 설치가 끝나면 service apache2 start 명령어를 이용하여 아파치 서버를 시작하고

웹 브라우저에서 서버의 IP주소 또는 도메인으로 접속했을 때 아래와 같은 페이지가 뜬다면 성공적으로 설치 된 것이다.



하지만 아직 ssl 적용이 되지 않았기 때문에 https://서버주소로 접속을 하면 접속이 되지 않을 것이다.


다음으로 sudo apt-get install openssl 명령어를 이용하여 openssl을 설치한 후 다음 순서대로 따라한다.


openssl genrsa -des3 -out server.key 2048 // 자가서명 인증서 생성 

openssl req -new -days 365 -key server.key -out server.csr // CSR 파일 생성 

cp server.key server.key.org 

openssl rsa -in server.key.org -out server.key // 개인키 패스워드 제거 

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt // 인증서 서명 

openssl x509 -in ca.der -inform DER -text // 인증서 인코딩 변경 

Apache 적용 
sudo a2enmod ssl 

sudo service apache2 restart 

sudo mkdir /etc/apache2/ssl // 인증서 폴더 생성 

위 작업에서 생성된 server.crt / server.csr / server.key 파일을 위에서 생성한 경로로 이동해 준다. 
 
Apache 설정 
sudo cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-available/서버주소      // default-ssl 파일을 사용중인 도메인주소로 변경
 
sudo vi /etc/apache2/sites-available/서버주소      // 편집기로 아래와 같이 내용 수정 
  SSLEngine on 
  SSLCertificateFile /etc/apache2/ssl/server.crt 
  SSLCertificateKeyFile /etc/apache2/ssl/server.key 

sudo a2ensite 서버주소 

sudo service apache2 restart // 서버 활성화 및 재시작

서버가 재시작 된 후에 https://서버주소로 접속하면 신뢰할 수 없는 인증기관 어쩌고 하는 내용이 뜨는데 
이것은 자가서명 인증서로 SSL을 구성하였으므로 당연한 현상이다.


vi 편집기 명령어는 다른 개발자분들이 쉽게 잘 설명해 놓은 자료들이 많으므로 조금만 검색하면 쉽게 찾을 수 있다.





+ Recent posts