======================== Push for iOS ======================== .. note:: 최신 샘플 및 라이브러리는 아래 링크를 통해, 다운로드 받을 수 있습니다. - `샘플 MADP - 모피어스 플랫폼 연동 `_ - `샘플 NATIVE - 네이티브 `_ 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를 주는 절차 .. _ApplicationID: Application ID ---------------- - App의 lic 파일에 포함된 application_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. Push 서비스 절차 ==================== 버전별 서비스 순서 ------------------------------ :ref:`UPMC` 3.5 이하 버전 토큰 요청 => :ref:`RegisterUser` => :ref:`RegisterService` => 메시지 수신 :ref:`UPMC` 3.6 이상 버전 :ref:`RegisterService` (자동으로 Token 요청) => :ref:`RegisterUser` => 메시지 수신 :ref:`UPMC` 4.0 이상 버전 :ref:`RegisterServiceAndUser` => 메시지 수신 DataFlow Diagram ------------------- .. figure:: ../_static/push/ios/apns-dataflow.png Sequence Diagram ------------------- .. figure:: ../_static/push/ios/apns-sequence.png 4. SDK 및 설정 파일 ======================= SDK 버전 -------------- - iOS 용 SDK 파일 - MPushLibrary.framework - APNS Push를 활용할 수 있는 라이브러리가 담긴 framework 파일 - MPushLibrary.bundle - MPushLibrary.framework 을 사용함에 있어 필요한 resource가 담긴 bundle 파일 - SDK 적용 방법 - XCode Project 에 Library 와 설정 파일에 추가 - MPushLibrary.framework - MPushLibrary.bundle - Manifest.xml - mcore.mobile.lic - 적용시 Project 내 파일이 없는 경우 Copy items if needed 선택 .. image:: ../_static/push/ios/xcode-setting-copy.png :width: 50% - 관련 Frameworks 추가 - XCode Project 설정 > Build Phases > Link Binary With Libraries > UserNotifications.framework 추가 - iOS10 대응을 위해 추가되는 UserNotifications.framework 을 추가하기 위해서는 XCode 8 이상 필요 플러그인 버전 -------------- - MPush 플러그인 파일 - MPush.framework - MPushLibrary 기반으로 구현된 Morpheus Push Plugin - MPush.bundle - MPush.framework 을 사용함에 있어 필요한 resource가 담긴 bundle 파일 - 플러그인 적용 방법 - IDE 에서 MPush Plugin 을 업데이트 후 적용 공통 설정 파일 -------------- - mcore.mobile.lic - Push 라이센스 정보가 담긴 Push 라이센스 파일 - application_id 값을 :ref:`ApplicationID` 로 사용 .. code-block:: text #Tue Feb 17 09:53:27 KST 2015 application_id=xxx.xxx.xxxx.xxxx expiration_date=xxxx-xx-xx mpsn=hZK................X sn=AhA....E.... .. versionadded:: 3.8.1 Library - 라이센스 파일을 바탕으로 생성한 Security Indexes 값으로 Push 서비스를 운용하는 중에 생성되는 사용자 또는 단말기의 식별 가능한 데이타를 암호화 하여 저장 - Manifest.xml - Push 구동을 위한 설정 파일 .. code-block:: xml ... y x.x http://pushxx.morpheus.co.kr:8080/upmc ... - settings.push.receiver 에 대한 설정값 ====================== ========== ============= Key Type Description ====================== ========== ============= log String Push Service 에 대한 Debugging 로그 출력 여부 ( y / n ) version String UPMC Version ( 3.0, 3.5, 3.6, 3.7, 3.8, 4.0 ) server String UPMC WAS 서버 URL ====================== ========== ============= 5. Push Service 연동 ======================= 라이브러리 버전 ----------------- Case #1. Push Notification 관련 UIApplicationDelegate 를 직접 연동 .. code-block:: objective-c #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; 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]; } Case #2. 로 바로 연동 .. code-block:: objective-c #import #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; return YES; } 플러그인 버전 ----------------- Case #1 - Push Notification 관련 UIApplicationDelegate 를 직접 연동 .. code-block:: objective-c #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; 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]; } Case #2 - 로 바로 연동 .. code-block:: objective-c #import #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; return YES; } 6. Push APIs ======================= Initialize with delegate --------------------------- .. c:function:: [[PushManager defaultManager] initializeWithDelegate:delegate] - Push Manager 를 시작하면서 delegate(대리자) 을 등록 - 등록된 delegate 을 통해 message 수신 등 push 와 괸련된 business logic controller 역활을 대행 - delegate 이 등록되지 않으면 앱이 시작되면서 전달받은 push message 들은 자동으로 지연 전달됨 .. versionchanged:: 3.6.4 :param id delegate: delegate 값, NotNull Register Service -------------------- .. c:function:: [[PushManager defaultManager] registerService:activity completionHandler:^(BOOL success) {}]; - Token 을 자동 요청하고 서비스 등록 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString token: token string 값, NotNull :param BlockHandler completionHandler: Service 등록 완료 후 호출, Nullable .. c:function:: [[PushManager defaultManager] registerService:activity token:@"TOKEN-STRING" completionHandler:^(BOOL success) {}]; - 직접 Token 값을 전달하여 서비스 등록 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString token: token string 값, NotNull :param BlockHandler completionHandler: Service 등록 완료 후 호출, Nullable - activity 가 UIViewController 가 아닌 경우 (id) 로 casting 하여 전달 .. code-block:: objective-c [[PushManager defaultManager] registerService:(id)activity completionHandler:^(BOOL success) {}]; Register User --------------- .. c:function:: [[PushManager defaultManager] registerUser:activity, clientUID:@"CUID" clientName:@"CNAME" completionHandler:^(BOOL success) {}]; - :ref:`CUID` 와 :ref:`CNAME` 으로 User 등록 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString clientUID: :ref:`CUID` 값, NotNull :param NSString clientName: :ref:`CNAME` 값, NotNull :param BlockHandler completionHandler: User 등록 완료 후 호출, Nullable Register Service and User -------------------------- .. c:function:: [[PushManager defaultManager] registerServiceAndUser:activity, clientUID:@"CUID" clientName:@"CNAME" completionHandler:^(BOOL success) {}]; - :ref:`CUID` 와 :ref:`CNAME` 으로 서비스 등록 및 User 등록을 동시 진행 .. versionchanged:: 4.0.0 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString clientUID: :ref:`CUID` 값, NotNull :param NSString clientName: :ref:`CNAME` 값, NotNull :param BlockHandler completionHandler: User 등록 완료 후 호출, Nullable Unregister Service -------------------- .. c:function:: [[PushManager defaultManager] unregisterService:activity completionHandler:^(BOOL success) {}]; - 서비스 해제 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param BlockHandler completionHandler: Service 해제 완료 후 호출, Nullable Register Group -------------------- .. c:function:: [[PushManager defaultManager] registerGroup:activity groupSequenceNumber:@"GROUP-NUMBER" completionHandler:^(BOOL success) {}]; - 현재 등록된 User 를 Group 에 등록 - 서버에 등록된 Group Sequence Number 값을 알고 있어야 등록 가능 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString groupSequenceNumber: Group Sequence Number 값, NotNull :param BlockHandler completionHandler: Group 등록 완료 후 호출, Nullable Unregister Group -------------------- .. c:function:: [[PushManager defaultManager] unregisterGroup:activity groupSequenceNumber:@"GROUP-NUMBER" completionHandler:^(BOOL success) {}]; - 현재 등록된 User 를 Group 에서 해제 - 서버에 등록된 Group Sequence Number 값을 알고 있어야 해제 가능 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString groupSequenceNumber: Group Sequence Number 값, NotNull :param BlockHandler completionHandler: Group 해제 완료 후 호출, Nullable Send Message -------------------- .. c:function:: [[PushManager defaultManager] send:activity clientUID:@"CUID" message:@"PUSH-MESSAGE" serviceCode:@"SERVICE-CODE" ext:@"EXT-DATA-JSON-STRING" completionHandler:^(BOOL success) {}]; - 앱에서 직접 Remote Push 발송 요청 - ServiceCode 는 서버에 미리 등록 후 발송 .. versionchanged:: 3.6.4 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString clientUID: :ref:`CUID` 값, NotNull :param NSString message: 발송할 Push Message, NotNull :param NSString serviceCode: 발송 Service Code, NotNull :param NSString ext: 확장 데이타로 발송할 String 으로 변환된 JSON 데이타를 전달, NotNull :param BlockHandler completionHandler: Group 해제 완료 후 호출, Nullable Read Message ---------------------- .. c:function:: [[PushManager defaultManager] read:activity messageUniqueKey:@"MESSAGE-UNIQUE-KEY" seqNo:@"SEQUENCE-NUMBER" completionHandler:^(BOOL success) {}]; - 읽음 확인 발송 - payload 에 전달된 messageuniquekey 값과 seqno 값을 추출하여 전달 - payload 에 messageuniquekey 은 Receiver 3.5 버전 이하에서만 전달됨 .. deprecated:: 3.6 Receiver :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString messageUniqueKey: Message Unique Key 값, NotNull :param NSString seqNo: Sequence Number 값, NotNull :param BlockHandler completionHandler: 읽음 확인 발송 완료 후 호출, Nullable .. c:function:: [[PushManager defaultManager] read:activity notification:userInfo completionHandler:^(BOOL success) {}]; - 읽음 확인 발송 - didReceiveRemoteNotification: 로 전달된 userInfo 를 그대로 전달 .. versionadded:: 3.6 UPMC :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSDictionary userInfo: 수신된 Notification 데이타, NotNull :param BlockHandler completionHandler: 읽음 확인 발송 완료 후 호출, Nullable Read Message for Enterprise ------------------------------ .. _PushManagerBadgeOption: PushManagerBadgeOption -------------------------- ============================== ============= Constant Description ============================== ============= PushManagerBadgeOptionKeep 서버에서 관리되는 counting 하나 줄여 count 를 유지시킴 PushManagerBadgeOptionReset 서버에서 관리되는 counting 을 0으로 reset PushManagerBadgeOptionUpdate 서버에서 관리되는 counting 을 특정 count 로 업데이트 PushManagerBadgeOptionForce 서버에서 관리되는 counting 을 Update API 를 통해 특정 count 로 업데이트 ============================== ============= .. c:function:: [[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOption completionHandler:^(BOOL success) {}]; - 엔터프라이즈 버전에서 읽음 확인 발송 - badge 정책을 badge option 으로 전달 .. versionadded:: 4.0EE UPMC :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSDictionary userInfo: 수신된 Notification 데이타, NotNull :param badgeOption: 수신된 Notification 데이타, NotNull :type badgeOption: :ref:`PushManagerBadgeOption` :param BlockHandler completionHandler: 읽음 확인 발송 완료 후 호출, Nullable Example: .. code-block:: objective-c [[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionKeep completionHandler:^(BOOL success) { }]; or [[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionReset completionHandler:^(BOOL success) { }]; .. c:function:: [[PushManager defaultManager] read:activity notification:userInfo badgeOption:badgeOption badge:badge completionHandler:^(BOOL success) {}]; - 엔터프라이즈 버전에서 읽음 확인 발송 - 읽음 확인에 대한 counting 을 특정 badge 값으로 업데이트 - 최소 1이상, 최대 1000 값 .. versionadded:: 4.0EE UPMC :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSDictionary userInfo: 수신된 Notification 데이타, NotNull :param badgeOption: 수신된 Notification 데이타, NotNull :type badgeOption: :ref:`PushManagerBadgeOption` :param NSNumber badge: 업데이트할 counting 값, 1-1000 :param BlockHandler completionHandler: 읽음 확인 발송 완료 후 호출, Nullable Example: .. code-block:: objective-c [[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionUpdate badge:@(10) completionHandler:^(BOOL success) { }]; .. c:function:: - (void)update:(UIViewController *)activity badge:(NSNumber *)badge completionHandler:(PushManagerNetworkCompletionHandler)handler - 읽음 확인에 대한 counting 을 강제로 특정 badge 값으로 업데이트 - 최소 1이상, 최대 1000 값 .. versionadded:: 4.0EE UPMC :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSNumber badge: 업데이트할 counting 값, 1-1000 :param BlockHandler completionHandler: 읽음 확인 발송 완료 후 호출, Nullable Example: .. code-block:: objective-c [[PushManager defaultManager] update:self badge:@(3) completionHandler:^(BOOL success) { }]; 7. PushManager Delegate ========================== .. _PushStatus: PushStatus -------------------------- Push Message 가 발송된 상태값 =========== ============= Constant Description =========== ============= START Push Message 로 앱을 시작한 경우 ACTIVE Application Forground Status 에서 Push Message 를 받은 경우 BACKGROUND Application Background Status 에서 Push Message 가 전달된 경우 =========== ============= Delegate 설정 ----------------------- Push Message 수신을 대행하는 대리자를 등록 .. c:function:: - (void)initilaizeWithDelegate:(id )delegate {} :param PushManagerDelegate delegate: PushManager 의 역활을 대행할 대리자 등록 Example: .. code-block:: objective-c [[PushManager defaultManager] initializeWithDelegate:self]; Push Message 수신 처리 ----------------------- .. c:function:: - (void)manager:(PushManager *)manager didReceiveRemoteNotification:(NSDictionary *)userInfo status:(NSString *)status {} .. deprecated:: 3.7.4 Library :param PushManager manager: PushManager Instance, NotNull :param NSDictionary userInfo: 수신된 Notification 데이타, NotNull :param status: 수신된 Notification 의 상태, NotNull :type status: :ref:`PushStatus` .. c:function:: - (void)manager:(PushManager *)manager didReceiveUserNotification:(NSDictionary *)userInfo status:(NSString *)status messageUID:(NSString *)messageUID {} .. versionadded:: 3.7.4 Library :param PushManager manager: PushManager Instance, NotNull :param NSDictionary userInfo: 수신된 Notification 데이타, NotNull :param status: 수신된 Notification 의 상태, NotNull :type status: :ref:`PushStatus` :param NSString messageUUID: 앱에서 부여한 수신된 메세지의 고유 ID, NotNull Example: .. code-block:: objective-c - (void)manager:(PushManager *)manager didReceiveUserNotification:(NSDictionary *)userInfo status:(NSString *)status messageUID:(NSString *)messageUID { PushManager *manager = [PushManager defaultManager]; NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; if ( [apsInfo objectForKey:@"badge"] ) { NSNumber *badge = [apsInfo objectForKey:@"badge"]; // 뱃지 숫자 변경 manager.notificationCenter.badgeNumber = badge; // 뱃지 숫자 초기화 manager.notificationCenter.badgeNumber = [NSNumber numberWithInteger:0]; } // 읽음 확인 [manager read:self notification:notification.userInfo completionHandler:^(BOOL success) { NSString *message = ( ! success ) ? @"Confirming Read-Message is FAIL !!" : @"Confirming Read-Message is SUCCESS !!"; NSLog( @"%@", message ); }]; // 알림 메세지 NSString *title = [NSString stringWithFormat:@"PUSH (%@)", status]; NSString *message = [apsInfo objectForKey:@"alert"]; if ( NSClassFromString(@"UIAlertController") ) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"취소" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]]; [alert addAction:[UIAlertAction actionWithTitle:@"확인" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; UIViewController *viewController = [[UIApplication sharedApplication] keyWindow].rootViewController; if ( viewController.presentedViewController ) { viewController = viewController.presentedViewController; } [viewController presentViewController:alert animated:YES completion:^{ }]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"취소" otherButtonTitles:@"확인", nil]; [alert show]; } } 8. APNS Push Payload ========================== UPMC 에서 APNS 로 발송되는 Payload JSON 형태 APNS Payload Keys (APN) -------------------------- APNS 로 보내지는 JSON dictionary object 에 기본적으로 정의되는 aps 대한 키값 정의 ================== ============= ===================================== Key Value Type Description ================== ============= ===================================== alert String Push Message 내용 badge Number 앱 아이콘에 Badge 표시, 값이 정의되지 않으면 변경되지 않음 sound String | Library/Sounds 폴더에 있는 파일명을 정의하면 알림시 Sound 와 함께 알림. 값이 정의되지 않으면 default 로 처리 ================== ============= ===================================== .. role:: strikethrough :class: strikethrough UPMC Payload Keys (MPS) -------------------------- APNS 로 보내지는 JSON dictionary object 에 UPMC에서 추가정의되는 mps 대한 키값 정의 ====================================== ============= ======================= Key Value Type Description ====================================== ============= ======================= appid String 발송 타겟의 :ref:`ApplicationID` 값 sender String 발송 주체 ( admin, device-android, device-ios ) seqno Number DB 처리되고 있는 ext String | 확장 데이타, 보통 JSON String 형태로 전달. 만약 데이타가 대용량(Rich)인 경우 서버에서 데이타를 HTML형태로 생성하여 해당 URL을 전달 senddate String 발송된 시간 :strikethrough:`messageuniquekey` String 발송된 메세지의 고유키 db_in String DB Insert 여부 ("Y" or "N") pushkey String 발송 대상에 대한 고유 키, 4.0EE 버전에서 출력 ====================================== ============= ======================= History: - 3.6 : senddate 추가 - 3.7 : messageuniquekey 제외, db_in 추가 Example: - Simple Data Push .. code-block:: json { "aps": { "alert": "", "badge": 1, "sound": "alert.aif" }, "mps": { "appid": "com.uracle.push.test", "seqno": "104", "sender": "admin", "senddate": "2016041417", "db_in": "N", "ext": "", "pushkey": "2b9256f6f959240f4dc5ea2f7ed4095ca693884d" } } - Rich Data Push .. code-block:: json { "aps": { "alert": "", "badge": 1, "sound": "alert.aif" }, "mps": { "appid": "com.uracle.push.test", "seqno": "387", "sender": "admin", "senddate": "2016041417", "db_in": "N", "ext": "http://domain.com:8080/resources/totalInfo/0414172200_msp.html", "pushkey": "2b9256f6f959240f4dc5ea2f7ed4095ca693884d" } } 9. APNS 인증서 발급시 주의사항 ========================== .. code-block:: json "1. 인증서가 만료(폐기)되었거나 발급받는 도중에 오류가 있으면, 처음부터 다시 발급받아볼 것" "2. java apns 라이브러리와 맞는 jdk를 사용 할 것(서버 실행시 java7을 사용하지말고 java6을 사용해볼 것)" "3. p12 파일을 생성할 때 인증서 1개만 내보내기로 생성할 것" 10. MUTABLE-CONTENT 수신확인 (iOS10 이상) ====================================== - 앱이 Background 또는 종료 상태일 경우에 Push Message가 mutable-content:1 타입으로 올 경우 Notification Service Extention에서 메시지를 우선 처리할수 있다. - iOS10 미만 단말기에서는 기존과 동일하게 처리. Notification Service Extention ------------------------------ 1. File -> New -> Target 선택 .. figure:: ../_static/push/ios/Notification-service_1.png 2. Notification Service Extention 선택 .. figure:: ../_static/push/ios/Notification-service_2.png 3. Product Name을 자유롭게 설정 .. figure:: ../_static/push/ios/Notification-service_3.png 4. Activate를 선택하면 Notification Service Extention Target 항목이 추가 .. figure:: ../_static/push/ios/Notification-service_4.png 5. 추가된 NotificationService.m 파일에 Push 관련 처리 .. figure:: ../_static/push/ios/Notification-service_5.png NotificationService.m 파일에서의 수신확인 ------------------------------------ 1. Push 관련 라이브러리 파일들 Target Membership에 NotificationService 타켓 추가 2. #import 추가 3. didReceiveNotificationRequest 메서드 내에 feedback 메서드 추가 Example: .. code-block:: objective-c // NotificationService 쪽에서 메시지 수신시 들어오는 이벤트 - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; //PushManager 초기화 PushManager *manager = [PushManager defaultManager]; //Keychain Sharing을 통해 feedback시 필요한 정보를 획득 //키체인 공유 외에도 앱그룹등을 통한 방법으로도 공유가 가능 (app과 extension 사이에 데이터 공유) NSString *app_identifier = [NSString stringWithFormat:@"%@.pushDic", @"com.uracle.push.demo.NotificationService"]; NSDictionary *pushDic = [KeychainController loadValueForKey:app_identifier forAccessGroup:@"com.uracle.push.demo.NotificationService"]; //관련정보가 없을 경우에는 feedback처리 없이 완료 if(pushDic == nil) { self.contentHandler(self.bestAttemptContent); return; } else { //데이터 공유시의 값의 정보 출처 샘플 //[pushDic setObject:[PushManager defaultManager].info.clientUID forKey:@"cuid"]; //[pushDic setObject:[PushManager defaultManager].info.pushServiceID forKey:@"psid"]; //[pushDic setObject:[PushManager defaultManager].info.host forKey:@"host"]; NSString *cuid = [pushDic objectForKey:@"cuid"]; NSString *psid = [pushDic objectForKey:@"psid"]; NSString *host = [pushDic objectForKey:@"host"]; if(host) { //서버 호스트 정보를 셋팅 [manager.info changeHost:host]; } if(cuid && psid) { //feedback API 호출 //push메시지 객체와 cuid, psid값이 필요 [manager feedback:self notification:self.bestAttemptContent.userInfo clientUID:cuid psID:psid completionHandler:^(BOOL success) { //앱에서 중복으로 feedback처리를 하지 않도록 메시지 객체에 feedback 정보에 대한 값을 셋팅후 전달 NSMutableDictionary *userInfo = [self.bestAttemptContent.userInfo mutableCopy]; [userInfo setObject:@"true" forKey:@"feedback"]; self.bestAttemptContent.userInfo = userInfo; self.contentHandler(self.bestAttemptContent); }]; } else { self.contentHandler(self.bestAttemptContent); } } } 11. Marketing Push API ====================================== - Manifest.xml - Manifest.xml 에 umpc 정보를 추가한다 .. code-block:: xml ... 30000 ... Update Session ---------------------- .. c:function:: [[PushManager defaultManager] updateSession:activity cuid:@"CUID" completionHandler:^(BOOL success, NSDictionary *body) {}]; - 세션 업데이트 - ClientID 값을 추출하여 전달 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString cuid: ClientID 값, NotNull :param BlockHandler completionHandler: 세션 업데이트 발송 완료 후 호출, Nullable Example: .. code-block:: objective-c [[PushManager defaultManager] updateSession:activity cuid:[PushManager defaultManager].info.clientUID completionHandler:^(BOOL success, NSDictionary *body) { }]; Update Purchase ---------------------- .. c:function:: [[PushManager defaultManager] updatePurchase:activity id:"CAMPAIGN-ID" cuid:@"CUID" completionHandler:^(BOOL success, NSDictionary *body) {}]; - 구매 이력 업데이트 - payload 에 전달된 Campaign 값을 추출하여 전달 - ClientID 값을 추출하여 전달 :param UIViewController activity: 호출하는 화면 전달, NotNull :param NSString id: Campaign ID 값, NotNull :param NSString cuid: ClientID 값, NotNull :param BlockHandler completionHandler: 구매 이력 업데이트 발송 완료 후 호출, Nullable Example: .. code-block:: objective-c [[PushManager defaultManager] updatePurchase:activity id:@"730" cuid:[PushManager defaultManager].info.clientUID completionHandler:^(BOOL success, NSDictionary *body) { }]; 12. APNS 인증키 p8 발급 따라하기 ====================================== - p8 키가 생성되어 있지 않을 경우 Apple 개발자 사이트에서 p8 Key 발급이 가능하다. 12.1. Apple 개발자 사이트 접속 ------------------- - https://developer.apple.com 사이트로 이동한다. - Account 메뉴를 눌러 로그인 화면으로 이동한다. .. figure:: ../_static/push/ios/3/3-1.png :scale: 70 % 12.2. Apple Developer에 로그인 ------------------- - 1번 항목에 애플 개발자 아이디, 2번 항목에 패스워드를 입력한다. .. figure:: ../_static/push/ios/3/3-2.png :scale: 70 % 12.3. Account ------------------- - Certificates, Identifiers & Profiles 메뉴로 이동한다. .. figure:: ../_static/push/ios/3/3-3.png :scale: 70 % 12.4. Certificates, Identifiers & Profiles ------------------- - Keys 메뉴로 이동한다. .. figure:: ../_static/push/ios/3/3-4.png :scale: 70 % 12.5. Keys ------------------- - 1번 항목에서 기존에 생성되어 있던 p8키를 확인할 수 있다. - p8키는 계정당 2개까지 생성이 가능하며 계정내에 모든앱이 함께 사용하는 부분으로 적절한 관리가 필요하다. - 2번(+버튼)을 눌러 키를 추가한다. .. figure:: ../_static/push/ios/3/3-5.png :scale: 70 % 12.6. Register a New Key ------------------- - 1번 항목에 Key 이름을 입력한다. - 2번 항목을 체크하여 APNS Key를 선택한다. - Continue를 눌러 다음 절차를 진행한다. .. figure:: ../_static/push/ios/3/3-6.png :scale: 70 % 12.7. APNS Key 생성중 ------------------- - 선택한 설정에 대한 내용을 보여준다. - Register를 눌러 키를 생성한다. .. figure:: ../_static/push/ios/3/3-7.png :scale: 70 % .. _p8_Key: 12.8. Download Your Key ------------------- - Download 버튼을 눌러 p8키를 다운로드 받는다. - p8키는 생성할때 1회 다운로드가 가능하고 이후 추가 다운로드가 불가하니 키 파일 관리에 유의해야 한다. .. figure:: ../_static/push/ios/3/3-8.png :scale: 70 % 12.9. Key ID ------------------- - `Apple 개발자 사이트 `_ -> Account -> Certificates, Identifiers & Profiles 메뉴로 이동한다. - Keys 탭에서 기존에 생성되어 있는 Key 리스트와 그 Key ID를 확인할수 있다. .. figure:: ../_static/push/ios/3/3-10.png :scale: 70 % 12.10. Team ID ------------------- - :ref:`p8_Key` 을 통해, 획득한 p8 파일과 Key ID를 확인한다. - `Apple 개발자 사이트 `_ -> Account -> MemberShip 에서 Team ID를 확인할 수 있다. .. figure:: ../_static/push/ios/3/3-9.png :scale: 70 %