======================== iOS ======================== *샘플 다운로드 ================== .. note:: 최신 샘플 및 라이브러리는 아래 링크를 통해, 다운로드 받을 수 있습니다. - :download:`샘플 다운로드 <../../_static/cloud/ios/pushcloud.zip>` 1. 개요 ========= Morpheus Push 는 스마트폰 OS에서 지원하는 PNS(Push Notification Server)를 기반으로 한 메세지 전송 플랫폼이다. iOS Client 에서는 UPMC WAS 에서 제공하는 Push API 를 각각 버전 규격에 맞춰 연동하여 원할하게 Push Service 를 운영하기 위한 라이브러리를 제공한다. 2. 용어 ========= .. _APNS: APNS -------- - Apple Push Notification Service 의 줄임말. - Apple 에서 직접 제공하는 영구적인 보안 채널에 공급자를 연결하여 대상 장치에 알림을 보낼 수 있는 서비스. .. _UPMC: UPMC -------- - Uracle Push Message Center 의 줄임말. - Apple APNS 서버와 TLS 인증으로 연결된 APNS Provider 서버를 Server 대 Server 로 연계하여 구동하는 WAS(Web Application Server) 이다. - Receiver 라고도 불림 .. _RegisterService: Service 등록 ------------------ - :ref:`APNS` 로 부터 Token 을 할당 받고 :ref:`UPMC` 로 Push 서비스를 사용하겠다고 등록하는 절차 .. _UnregisterService: Service 해제 ------------------ - :ref:`UPMC` 로 Push 서비스를 사용하지 않겠다고 등록을 삭제하는 절차 .. _RegisterUser: User 등록 ------------- - :ref:`UPMC` 로 Push 서비스에 대한 사용자를 등록 또는 변경하는 절차 .. _RegisterServiceAndUser: ServiceAndUser 등록 ---------------------- - :ref:`UPMC` 로 Push 서비스 등록 및 사용자를 등록을 동시에 진행하는 절차 .. _FeedbackMessage: 수신 확인 ------------- - 메세지를 제대로 받았을 때 :ref:`UPMC` 로 Ack를 주는 절차 .. _ReadMessage: 읽음 확인 ------------- - App에서 메세지를 읽었을때 :ref:`UPMC` 로 Ack를 주는 절차 .. _ProjectID: Project ID ---------------- - Push 서비스 이용을 위해 Dev Console에서 발급받은 ID .. _CUID: Client ID ---------- - 사용자로 등록할 Client 의 고유한 ID (CUID 라고도 함) - Email, UserID, Phone Number 또는 Device-UUID 등을 CUID 로 사용 .. _CNAME: Client Name ------------ - 사용자로 등록할 Client 의 이름 (CNAME 라고도 함) - 사용자의 이름이나 Nickname 또는 Device Name 을 CNAME 으로 사용 .. _GROUPSEQ_IOS: GROUPSEQ ------------ - Group Sequence Number 의 준말로 User Group의 고유한 Sequence Number .. _PSID: PSID ------------ - Push Service ID 의 줄임말 - Push 서비스에 대한 고유 ID - APNS에서 할당 받은 Device Token을 사용 3. APNS 인증키 p8 발급 따라하기 ==================== - p8 키가 생성되어 있지 않을 경우 Apple 개발자 사이트에서 p8 Key 발급이 가능하다. 3.1. Apple 개발자 사이트 접속 ------------------- - https://developer.apple.com 사이트로 이동한다. - Account 메뉴를 눌러 로그인 화면으로 이동한다. .. figure:: ../../_static/cloud/ios/3/3-1.png :scale: 70 % 3.2. Apple Developer에 로그인 ------------------- - 1번 항목에 애플 개발자 아이디, 2번 항목에 패스워드를 입력한다. .. figure:: ../../_static/cloud/ios/3/3-2.png :scale: 70 % 3.3. Account ------------------- - Certificates, Identifiers & Profiles 메뉴로 이동한다. .. figure:: ../../_static/cloud/ios/3/3-3.png :scale: 70 % 3.4. Certificates, Identifiers & Profiles ------------------- - Keys 메뉴로 이동한다. .. figure:: ../../_static/cloud/ios/3/3-4.png :scale: 70 % 3.5. Keys ------------------- - 1번 항목에서 기존에 생성되어 있던 p8키를 확인할 수 있다. - p8키는 계정당 2개까지 생성이 가능하며 계정내에 모든앱이 함께 사용하는 부분으로 적절한 관리가 필요하다. - 2번(+버튼)을 눌러 키를 추가한다. .. figure:: ../../_static/cloud/ios/3/3-5.png :scale: 70 % 3.6. Register a New Key ------------------- - 1번 항목에 Key 이름을 입력한다. - 2번 항목을 체크하여 APNS Key를 선택한다. - Continue를 눌러 다음 절차를 진행한다. .. figure:: ../../_static/cloud/ios/3/3-6.png :scale: 70 % 3.7. APNS Key 생성중 ------------------- - 선택한 설정에 대한 내용을 보여준다. - Register를 눌러 키를 생성한다. .. figure:: ../../_static/cloud/ios/3/3-7.png :scale: 70 % .. _p8_Key: 3.8. Download Your Key ------------------- - Download 버튼을 눌러 p8키를 다운로드 받는다. - p8키는 생성할때 1회 다운로드가 가능하고 이후 추가 다운로드가 불가하니 키 파일 관리에 유의해야 한다. .. figure:: ../../_static/cloud/ios/3/3-8.png :scale: 70 % 3.9. Key ID ------------------- - `Apple 개발자 사이트 `_ -> Account -> Certificates, Identifiers & Profiles 메뉴로 이동한다. - Keys 탭에서 기존에 생성되어 있는 Key 리스트와 그 Key ID를 확인할수 있다. .. figure:: ../../_static/cloud/ios/3/3-10.png :scale: 70 % 3.10. Team ID ------------------- - :ref:`p8_Key` 을 통해, 획득한 p8 파일과 Key ID를 확인한다. - `Apple 개발자 사이트 `_ -> Account -> MemberShip 에서 Team ID를 확인할 수 있다. - `서비스 설정 `_ 시 위의 파일과 값을 사용한다. .. figure:: ../../_static/cloud/ios/3/3-9.png :scale: 70 % 4. SDK 및 설정 파일 ======================= SDK 파일 -------------- - iOS 용 SDK 파일 - MPushLibrary.framework - APNS Push를 활용할 수 있는 라이브러리가 담긴 framework 파일 - MPushLibrary.bundle - MPushLibrary.framework 을 사용함에 있어 필요한 resource가 담긴 bundle 파일 - iOS 용 샘플 파일 - PushRecevier - PushManagerDelegate 대리자 샘플 파일 - 관련 Frameworks 추가 - XCode Project 설정 > Build Phases > Link Binary With Libraries > UserNotifications.framework 추가 - iOS10 대응을 위해 추가되는 UserNotifications.framework 을 추가하기 위해서는 XCode 8 이상 필요 공통 설정 파일 -------------- - Manifest.xml - Push 구동을 위한 설정 파일 .. code-block:: xml ... y x.x http://pushxx.morpheus.co.kr:8080/upmc xxxxxxxxxxxxxxxxxxxxxxx ... - settings.push.receiver 에 대한 설정값 ====================== ========== ============= Key Type Description ====================== ========== ============= project-id String Push 프로젝트 생성시 발급된 Project-ID log String Push Service 에 대한 Debugging 로그 출력 여부 ( y / n ) version String UPMC Version ( 5.0 ) server String UPMC WAS 서버 URL ====================== ========== ============= 5. 프로젝트 생성 따라하기 ==================== - iOS 프로젝트를 생성한다. Xcode11.3 버전을 기준으로 작성됨 5.1. Create a new Xcode project ------------------- - 템플릿 어플리케이션을 선택하고 Next를 눌러 다음 절차를 진행한다. .. figure:: ../../_static/cloud/ios/5/5-1.png :scale: 70 % 5.2. 새 프로젝트 설정 ------------------- - 설정 항목들은 앱을 생성후 변경이 가능하다. - 1번 항목에 프로젝트 이름을 입력한다. - 2번 항목은 Apple Developer Team을 선택하는 부분으로 연동된 개발자 계정이 없을 경우 None으로 설정된다. - 3번 항목은 앱의 고유한 아이디 값으로 앱을 구별하는 기준이 된다. - Objective-C를 기준으로 적용방법이 가이드 - Next를 눌러 다음 절차를 진행한다. .. figure:: ../../_static/cloud/ios/5/5-2.png :scale: 70 % 5.3. 프로젝트 생성 경로 설정 ------------------- - 프로젝트가 생성될 위치를 선택하고 프로젝트를 생성한다. .. figure:: ../../_static/cloud/ios/5/5-3.png :scale: 70 % 6. 프로젝트에 Push SDK 적용 ======================= 6.1. Push SDK 프로젝트에 drag & drop ------------------- - 1번 항목에서 라이브러리 파일 MPushLibrary.framework 와 MPushLibrary.bundle을 확인할 수 있다. - Custom 파일과 Manifest.xml 파일이 포함된 2번 폴더 전체를 프로젝트에 드래그하여 추가한다. - Custom 파일은 사용방법에 따라 추가하지 않을수 있으며 라이브러리와 Manifest.xml 은 반드시 포함되어야 한다. .. figure:: ../../_static/cloud/ios/6/6-1.png :scale: 70 % 6.2. Push SDK 프로젝트에 추가(옵션) ------------------- - 1번 항목이 체크되어 있으면 프로젝트 폴더에 드래그한 파일이 복사된다. - Create groups 옵션이 선택되어 있는지 확인한다. - Finish를 선택하여 SDK 추가 .. figure:: ../../_static/cloud/ios/6/6-2.png :scale: 70 % 6.3. Push SDK 프로젝트에 추가(완료) ------------------- - 1번 항목에서 SDK가 추가된 것을 확인할 수 있다. - Target -> Build Phases -> Link Binary With Libraries 항목에서 추가된 framework를 확인할 수 있다. .. figure:: ../../_static/cloud/ios/6/6-3.png :scale: 70 % 6.4. 프로젝트 Push 설정 ------------------- - iOS Push를 사용하기 위해서는 Capabilities 항목에 Push Notifications를 추가해 주어야 한다. - Target -> Signing & Capabilities 메뉴에서 + Capabilities 항목을 선택한다. .. figure:: ../../_static/cloud/ios/6/6-4.png :scale: 70 % 6.5. 프로젝트 Push 설정(Capabilities) ------------------- - 팝업에서 Push Notifications 항목을 선택한다. .. figure:: ../../_static/cloud/ios/6/6-5.png :scale: 70 % 6.6. 프로젝트 Push 설정(완료) ------------------- - Push Notifications 항목이 추가된 것을 확인할 수 있다. - 프로젝트이름.entitlements 파일이 추가된 것을 확인할 수 있다. .. figure:: ../../_static/cloud/ios/6/6-6.png :scale: 70 % 6.7. Push 라이브러리 초기화 ----------------- - 일반적으로 Appdelegate.m 파일에서 Push 라이브러리를 초기화한다. Case #1. 로 바로 연동 .. code-block:: objective-c #import // (optional) PushManagerDelegate 대리자를 설정할 경우 #import "PushReceiver.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; // (optional) PushManagerDelegate 대리자를 설정할 경우 [[PushManager defaultManager] initilaizeWithDelegate:[[PushReceiver alloc] init]]; return YES; } Case #2. Push Notification 관련 UIApplicationDelegate 를 직접 연동하여 처리할 경우 .. code-block:: objective-c #import // (optional) PushManagerDelegate 대리자를 설정할 경우 #import "PushReceiver.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; // (optional) PushManagerDelegate 대리자를 설정할 경우 [[PushManager defaultManager] initilaizeWithDelegate:[[PushReceiver alloc] init]]; return YES; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[PushManager defaultManager] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [[PushManager defaultManager] application:application didFailToRegisterForRemoteNotificationsWithError:error]; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[PushManager defaultManager] application:application didReceiveLocalNotification:notification]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [[PushManager defaultManager] application:application didReceiveRemoteNotification:userInfo]; } /* // Background 모드에서 호출하는 경우에 사용 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [[PushManager defaultManager] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } */ - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [[PushManager defaultManager] application:application didRegisterUserNotificationSettings:notificationSettings]; } 7. 프로젝트 빌드 ======================= - APNS 테스트의 경우 Simulator에서는 APNS TOKEN값이 발급되지 않아 테스트가 불가하다. - iOS 디바이스 빌드를 위해서는 애플아이디, 인증서, 프로비저닝 프로파일 등이 필요하다. - 코드서명 https://developer.apple.com/kr/support/code-signing 7.1. 빌드 준비 ------------------- - 1번: 인증서, 프로비저닝 프로파일을 수동으로 셋팅할지 자동으로 셋팅할지 여부를 체크 - 2번: Team을 선택하기 위해서는 Preferences 메뉴에 Apple ID가 등록되어 있어야 한다. - 3번: 빌드를 위한 셋팅중 오류가 발생하면 관련 오류 메시지가 표기된다. - 4번: Xcode -> Preferences 메뉴를 선택하여 Apple ID를 추가한다. .. figure:: ../../_static/cloud/ios/7/7-1.png :scale: 70 % 7.2. Apple ID 연동 ------------------- - 애플 개발자사이트에 등록되어 있는 Apple ID를 XCode와 연동하는 과정이다. - 1번: Accounts메뉴를 선택하면 등록되어 있는 계정등의 정보 확인이 가능하다. - 2번 +버튼을 누르고 3번 Apple ID를 선택한다. .. figure:: ../../_static/cloud/ios/7/7-2.png :scale: 70 % 7.3. Apple ID 연동(계정입력) ------------------- - Apple ID와 Password를 입력하고 Next를 눌러 계정을 추가한다. .. figure:: ../../_static/cloud/ios/7/7-3.png :scale: 70 % 7.4. Apple ID 연동(완료) ------------------- - 1번: 선택된 계정에 생성되어 있는 프로비저닝 프로파일을 다운로드한다. - 2번: 선택된 계정에 인증서를 생성 편집등을 할수 있는 편집창을 띄운다. .. figure:: ../../_static/cloud/ios/7/7-4.png :scale: 70 % 7.5. Automatically Manage signing ------------------- - 등록되어 있는 Apple ID를 기준으로 Team을 선택할수 있다. - 빌드 셋팅 관련 오류 메시지가 사라지면 정상적으로 연결된 단말기에 빌드할 수 있다. .. figure:: ../../_static/cloud/ios/7/7-5.png :scale: 70 % 7.6. Manually Manage signing ------------------- - Automatically Manage signing을 해제하면 맥에 설치되어 있는 인증서, 프로비저닝 프로파일 기준으로 설정할 수 있다 - Provisioning Profile 에서 설치된 프로비저닝 프로파일을 선택할 수 있다. .. figure:: ../../_static/cloud/ios/7/7-6.png :scale: 70 % 7.7. Signing 메뉴 ------------------- - 프로젝트 -> Target -> Build Settings에서 Signing 메뉴에서 signing에 대한 설정을 할수 있다. .. figure:: ../../_static/cloud/ios/7/7-7.png :scale: 70 % 7.8. 로그 보기 ------------------- - 코드서명이 정상적으로 준비가 되면 연결된 Target Device를 선택한다. - run 버튼을 누르면 하단 창이 활상화 되고 하단창이 열리지 않을 경우 3번 버튼을 클릭하여 활성화할 수 있다. - 하단창의 로그가 보이지 않을 경우 4번이 비활성화 되어 있는지 확인 - Manifest.xml 파일에서 log가 y로 되어 있을 경우에만 Push 관련 로그가 표기 - Push 라이브러리가 정상적으로 초기화가 되면 화면과 같은 로그를 확인할 수 있다. .. figure:: ../../_static/cloud/ios/7/7-8.png :scale: 70 % 7.9. APNS_MODE ------------------- - APNS_MODE는 서버에서 메시지 발송시 APNS서버를 TEST로 발송할지 REAL로 발송할지의 대한 여부값이 된다. - APNS_MODE값이 일치하지 않을 경우 메시지 발송시 Bad Device Token오류가 발생한다. - RegisterServiceAndUser API호출시 서버에 해당값을 전달한다. - Push 라이브러리 초기화시 값이 설정되며 default 값은 REAL (5.0.4 버전 이상시 mobileprovision 값을 체크하여 라이브러리에서 자동으로 초기화) - 개발용 인증서로 앱을 빌드시 APNS TOKEN값은 TEST토큰값이므로 DEV설정 필요하다. - [[PushManager defaultManager].info changeMode:@"DEV"]; .. figure:: ../../_static/cloud/ios/7/7-9.png :scale: 70 %