Push for iOS¶
1. 개요¶
Morpheus Push 는 스마트폰 OS에서 지원하는 PNS(Push Notification Server)를 기반으로 한 메세지 전송 플랫폼이다. iOS Client 에서는 UPMC WAS 에서 제공하는 Push API 를 각각 버전 규격에 맞춰 연동하여 원할하게 Push Service 를 운영하기 위한 라이브러리를 제공한다.
2. 용어¶
APNS¶
Apple Push Notification Service 의 줄임말.
Apple 에서 직접 제공하는 영구적인 보안 채널에 공급자를 연결하여 대상 장치에 알림을 보낼 수 있는 서비스.
UPMC¶
Uracle Push Message Center 의 줄임말.
Apple APNS 서버와 TLS 인증으로 연결된 APNS Provider 서버를 Server 대 Server 로 연계하여 구동하는 WAS(Web Application Server) 이다.
Receiver 라고도 불림
Application ID¶
App의 lic 파일에 포함된 application_id 값으로 앱을 구분하기 위한 코드값.
Client ID¶
사용자로 등록할 Client 의 고유한 ID (CUID 라고도 함)
Email, UserID, Phone Number 또는 Device-UUID 등을 CUID 로 사용
Client Name¶
사용자로 등록할 Client 의 이름 (CNAME 라고도 함)
사용자의 이름이나 Nickname 또는 Device Name 을 CNAME 으로 사용
GROUPSEQ¶
– Group Sequence Number 의 준말로 User Group의 고유한 Sequence Number
PSID¶
– Push Service ID 의 줄임말 - Push 서비스에 대한 고유 ID - APNS에서 할당 받은 Device Token을 사용
3. Push 서비스 절차¶
버전별 서비스 순서¶
UPMC 3.5 이하 버전
토큰 요청 => User 등록 => Service 등록 => 메시지 수신
UPMC 3.6 이상 버전
Service 등록 (자동으로 Token 요청) => User 등록 => 메시지 수신
UPMC 4.0 이상 버전
Service 등록 및 사용자 등록 => 메시지 수신
DataFlow Diagram¶
Sequence Diagram¶
4. SDK 및 설정 파일¶
SDK 버전¶
iOS 용 SDK 파일
MPushLibrary.framework
APNS Push를 활용할 수 있는 라이브러리가 담긴 framework 파일
MPushLibrary.bundle
MPushLibrary.framework 을 사용함에 있어 필요한 resource가 담긴 bundle 파일
SDK 적용 방법
관련 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 값을 Application ID 로 사용
#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....New in version 3.8.1: Library
라이센스 파일을 바탕으로 생성한 Security Indexes 값으로 Push 서비스를 운용하는 중에 생성되는 사용자 또는 단말기의 식별 가능한 데이타를 암호화 하여 저장
Manifest.xml
Push 구동을 위한 설정 파일
<manifest useDirectView="false"> ... <settings> <push> <receiver> <log>y</log> <version>x.x</version> <server>http://pushxx.morpheus.co.kr:8080/upmc</server> </receiver> </push> </settings> ... </manifest>
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 를 직접 연동
#import <MPushLibrary/PushManager.h> - (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. <MPushLibrary/AppDelegate+PushManager.h> 로 바로 연동
#import <MPushLibrary/PushManager.h> #import <MPushLibrary/AppDelegate+PushManager.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; return YES; }
플러그인 버전¶
Case #1 - Push Notification 관련 UIApplicationDelegate 를 직접 연동
#import <MPush/PushManager.h> - (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 - <MPush/AppDelegate+PushManager.h> 로 바로 연동
#import <MPush/PushManager.h> #import <MPush/AppDelegate+PushManager.h> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [[PushManager defaultManager] application:application didFinishLaunchingWithOptions:launchOptions]; return YES; }
6. Push APIs¶
Initialize with delegate¶
[[PushManager defaultManager] initializeWithDelegate:delegate]
Push Manager 를 시작하면서 delegate(대리자) 을 등록
등록된 delegate 을 통해 message 수신 등 push 와 괸련된 business logic controller 역활을 대행
delegate 이 등록되지 않으면 앱이 시작되면서 전달받은 push message 들은 자동으로 지연 전달됨
Changed in version 3.6.4.
- Parameters
delegate (id<PushManagerDelegate>) – delegate 값, NotNull
Register Service¶
[[PushManager defaultManager] registerService:activity completionHandler:^(BOOL success) {}];
Token 을 자동 요청하고 서비스 등록
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
token (NSString) – token string 값, NotNull
completionHandler (BlockHandler) – Service 등록 완료 후 호출, Nullable
[[PushManager defaultManager] registerService:activity token:@"TOKEN-STRING" completionHandler:^(BOOL success) {}];
직접 Token 값을 전달하여 서비스 등록
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
token (NSString) – token string 값, NotNull
completionHandler (BlockHandler) – Service 등록 완료 후 호출, Nullable
activity 가 UIViewController 가 아닌 경우 (id) 로 casting 하여 전달
[[PushManager defaultManager] registerService:(id)activity completionHandler:^(BOOL success) {}];
Register User¶
[[PushManager defaultManager] registerUser:activity, clientUID:@"CUID" clientName:@"CNAME" completionHandler:^(BOOL success) {}];
Client ID 와 Client Name 으로 User 등록
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
clientUID (NSString) – Client ID 값, NotNull
clientName (NSString) – Client Name 값, NotNull
completionHandler (BlockHandler) – User 등록 완료 후 호출, Nullable
Register Service and User¶
[[PushManager defaultManager] registerServiceAndUser:activity, clientUID:@"CUID" clientName:@"CNAME" completionHandler:^(BOOL success) {}];
Client ID 와 Client Name 으로 서비스 등록 및 User 등록을 동시 진행
Changed in version 4.0.0.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
clientUID (NSString) – Client ID 값, NotNull
clientName (NSString) – Client Name 값, NotNull
completionHandler (BlockHandler) – User 등록 완료 후 호출, Nullable
Unregister Service¶
[[PushManager defaultManager] unregisterService:activity completionHandler:^(BOOL success) {}];
서비스 해제
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
completionHandler (BlockHandler) – Service 해제 완료 후 호출, Nullable
Register Group¶
[[PushManager defaultManager] registerGroup:activity groupSequenceNumber:@"GROUP-NUMBER" completionHandler:^(BOOL success) {}];
현재 등록된 User 를 Group 에 등록
서버에 등록된 Group Sequence Number 값을 알고 있어야 등록 가능
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
groupSequenceNumber (NSString) – Group Sequence Number 값, NotNull
completionHandler (BlockHandler) – Group 등록 완료 후 호출, Nullable
Unregister Group¶
[[PushManager defaultManager] unregisterGroup:activity groupSequenceNumber:@"GROUP-NUMBER" completionHandler:^(BOOL success) {}];
현재 등록된 User 를 Group 에서 해제
서버에 등록된 Group Sequence Number 값을 알고 있어야 해제 가능
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
groupSequenceNumber (NSString) – Group Sequence Number 값, NotNull
completionHandler (BlockHandler) – Group 해제 완료 후 호출, Nullable
Send Message¶
[[PushManager defaultManager] send:activity clientUID:@"CUID" message:@"PUSH-MESSAGE" serviceCode:@"SERVICE-CODE" ext:@"EXT-DATA-JSON-STRING" completionHandler:^(BOOL success) {}];
앱에서 직접 Remote Push 발송 요청
ServiceCode 는 서버에 미리 등록 후 발송
Changed in version 3.6.4.
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
clientUID (NSString) – Client ID 값, NotNull
message (NSString) – 발송할 Push Message, NotNull
serviceCode (NSString) – 발송 Service Code, NotNull
ext (NSString) – 확장 데이타로 발송할 String 으로 변환된 JSON 데이타를 전달, NotNull
completionHandler (BlockHandler) – Group 해제 완료 후 호출, Nullable
Read Message¶
[[PushManager defaultManager] read:activity messageUniqueKey:@"MESSAGE-UNIQUE-KEY" seqNo:@"SEQUENCE-NUMBER" completionHandler:^(BOOL success) {}];
읽음 확인 발송
payload 에 전달된 messageuniquekey 값과 seqno 값을 추출하여 전달
payload 에 messageuniquekey 은 Receiver 3.5 버전 이하에서만 전달됨
Deprecated since version 3.6: Receiver
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
messageUniqueKey (NSString) – Message Unique Key 값, NotNull
seqNo (NSString) – Sequence Number 값, NotNull
completionHandler (BlockHandler) – 읽음 확인 발송 완료 후 호출, Nullable
[[PushManager defaultManager] read:activity notification:userInfo completionHandler:^(BOOL success) {}];
읽음 확인 발송
didReceiveRemoteNotification: 로 전달된 userInfo 를 그대로 전달
New in version 3.6: UPMC
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
userInfo (NSDictionary) – 수신된 Notification 데이타, NotNull
completionHandler (BlockHandler) – 읽음 확인 발송 완료 후 호출, Nullable
Read Message for Enterprise¶
PushManagerBadgeOption¶
Constant
Description
PushManagerBadgeOptionKeep
서버에서 관리되는 counting 하나 줄여 count 를 유지시킴
PushManagerBadgeOptionReset
서버에서 관리되는 counting 을 0으로 reset
PushManagerBadgeOptionUpdate
서버에서 관리되는 counting 을 특정 count 로 업데이트
PushManagerBadgeOptionForce
서버에서 관리되는 counting 을 Update API 를 통해 특정 count 로 업데이트
[[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOption completionHandler:^(BOOL success) {}];
엔터프라이즈 버전에서 읽음 확인 발송
badge 정책을 badge option 으로 전달
New in version 4.0EE: UPMC
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
userInfo (NSDictionary) – 수신된 Notification 데이타, NotNull
badgeOption (PushManagerBadgeOption) – 수신된 Notification 데이타, NotNull
completionHandler (BlockHandler) – 읽음 확인 발송 완료 후 호출, Nullable
Example:
[[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionKeep completionHandler:^(BOOL success) { }]; or [[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionReset completionHandler:^(BOOL success) { }];
[[PushManager defaultManager] read:activity notification:userInfo badgeOption:badgeOption badge:badge completionHandler:^(BOOL success) {}];
엔터프라이즈 버전에서 읽음 확인 발송
읽음 확인에 대한 counting 을 특정 badge 값으로 업데이트
최소 1이상, 최대 1000 값
New in version 4.0EE: UPMC
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
userInfo (NSDictionary) – 수신된 Notification 데이타, NotNull
badgeOption (PushManagerBadgeOption) – 수신된 Notification 데이타, NotNull
badge (NSNumber) – 업데이트할 counting 값, 1-1000
completionHandler (BlockHandler) – 읽음 확인 발송 완료 후 호출, Nullable
Example:
[[PushManager defaultManager] read:activity notification:userInfo badgeOption:PushManagerBadgeOptionUpdate badge:@(10) completionHandler:^(BOOL success) { }];
- (void)update:(UIViewController *)activity badge:(NSNumber *)badge completionHandler:(PushManagerNetworkCompletionHandler)handler
읽음 확인에 대한 counting 을 강제로 특정 badge 값으로 업데이트
최소 1이상, 최대 1000 값
New in version 4.0EE: UPMC
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
badge (NSNumber) – 업데이트할 counting 값, 1-1000
completionHandler (BlockHandler) – 읽음 확인 발송 완료 후 호출, Nullable
Example:
[[PushManager defaultManager] update:self badge:@(3) completionHandler:^(BOOL success) { }];
7. PushManager Delegate¶
PushStatus¶
Push Message 가 발송된 상태값
Constant
Description
START
Push Message 로 앱을 시작한 경우
ACTIVE
Application Forground Status 에서 Push Message 를 받은 경우
BACKGROUND
Application Background Status 에서 Push Message 가 전달된 경우
Delegate 설정¶
Push Message 수신을 대행하는 대리자를 등록
- (void)initilaizeWithDelegate:(id <PushManagerDelegate>)delegate {}
- Parameters
delegate (PushManagerDelegate) – PushManager 의 역활을 대행할 대리자 등록
Example:
[[PushManager defaultManager] initializeWithDelegate:self];
Push Message 수신 처리¶
- (void)manager:(PushManager *)manager didReceiveRemoteNotification:(NSDictionary *)userInfo status:(NSString *)status {}
Deprecated since version 3.7.4: Library
- Parameters
manager (PushManager) – PushManager Instance, NotNull
userInfo (NSDictionary) – 수신된 Notification 데이타, NotNull
status (PushStatus) – 수신된 Notification 의 상태, NotNull
- (void)manager:(PushManager *)manager didReceiveUserNotification:(NSDictionary *)userInfo
status:(NSString *)status messageUID:(NSString *)messageUID {}
New in version 3.7.4: Library
- Parameters
manager (PushManager) – PushManager Instance, NotNull
userInfo (NSDictionary) – 수신된 Notification 데이타, NotNull
status (PushStatus) – 수신된 Notification 의 상태, NotNull
messageUUID (NSString) – 앱에서 부여한 수신된 메세지의 고유 ID, NotNull
Example:
- (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 로 처리
UPMC Payload Keys (MPS)¶
APNS 로 보내지는 JSON dictionary object 에 UPMC에서 추가정의되는 mps 대한 키값 정의
Key
Value Type
Description
appid
String
발송 타겟의 Application ID 값
sender
String
발송 주체 ( admin, device-android, device-ios )
seqno
Number
DB 처리되고 있는
ext
String
확장 데이타, 보통 JSON String 형태로 전달. 만약 데이타가 대용량(Rich)인 경우 서버에서 데이타를 HTML형태로 생성하여 해당 URL을 전달senddate
String
발송된 시간
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
{ "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
{ "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 인증서 발급시 주의사항¶
"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¶
- File -> New -> Target 선택
![]()
- Notification Service Extention 선택
![]()
- Product Name을 자유롭게 설정
![]()
- Activate를 선택하면 Notification Service Extention Target 항목이 추가
![]()
- 추가된 NotificationService.m 파일에 Push 관련 처리
![]()
NotificationService.m 파일에서의 수신확인¶
Push 관련 라이브러리 파일들 Target Membership에 NotificationService 타켓 추가
#import <MPushLibrary/MPushLibrary.h> 추가
didReceiveNotificationRequest 메서드 내에 feedback 메서드 추가
Example:
// 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 정보를 추가한다
<manifest useDirectView="false"> ... <settings> <push> <umpc> <!-- umpc 서버 정보 --> <server></server> <!-- 타임아웃 정보 --> <timeout>30000</timeout> </umpc> </push> </settings> ... </manifest>
Update Session¶
[[PushManager defaultManager] updateSession:activity cuid:@"CUID" completionHandler:^(BOOL success, NSDictionary *body) {}];
세션 업데이트
ClientID 값을 추출하여 전달
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
cuid (NSString) – ClientID 값, NotNull
completionHandler (BlockHandler) – 세션 업데이트 발송 완료 후 호출, Nullable
Example:
[[PushManager defaultManager] updateSession:activity cuid:[PushManager defaultManager].info.clientUID completionHandler:^(BOOL success, NSDictionary *body) { }];
Update Purchase¶
[[PushManager defaultManager] updatePurchase:activity id:"CAMPAIGN-ID" cuid:@"CUID" completionHandler:^(BOOL success, NSDictionary *body) {}];
구매 이력 업데이트
payload 에 전달된 Campaign 값을 추출하여 전달
ClientID 값을 추출하여 전달
- Parameters
activity (UIViewController) – 호출하는 화면 전달, NotNull
id (NSString) – Campaign ID 값, NotNull
cuid (NSString) – ClientID 값, NotNull
completionHandler (BlockHandler) – 구매 이력 업데이트 발송 완료 후 호출, Nullable
Example:
[[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 메뉴를 눌러 로그인 화면으로 이동한다.
12.2. Apple Developer에 로그인¶
12.3. Account¶
12.4. Certificates, Identifiers & Profiles¶
12.5. Keys¶
12.6. Register a New Key¶
12.7. APNS Key 생성중¶
12.8. Download Your Key¶
12.9. Key ID¶
Apple 개발자 사이트 -> Account -> Certificates, Identifiers & Profiles 메뉴로 이동한다.
Keys 탭에서 기존에 생성되어 있는 Key 리스트와 그 Key ID를 확인할수 있다.
12.10. Team ID¶
12.8. Download Your Key 을 통해, 획득한 p8 파일과 Key ID를 확인한다.
Apple 개발자 사이트 -> Account -> MemberShip 에서 Team ID를 확인할 수 있다.