DeviceToken은 OS에 의해 변경될 수 있습니다. 따라서, 앱 실행 시마다 호출해야 합니다.
핑거푸시 모든 API는 기기 등록 API(register) 성공 후 사용할 수 있습니다.
//기기등록
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//핑거푸시의 모든 api를 사용하기 위해서 기기등록 우선
finger.sharedData().registerUser(withBlock: deviceToken, { (posts, error) -> Void in
if error != nil{
print("기기 등록 : \(posts)")
} else {
//이미등록(504, 201) 무시.
print("기기 등록 error : \(error)")
}
})
}
//기기등록
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//핑거푸시의 모든 api를 사용하기 위해서 기기등록 우선
[[finger sharedData] registerUserWithBlock:deviceToken :^(NSString *posts, NSError *error) {
if (!error)
{
NSLog(@"기기등록 %@", posts);
}else{
//이미등록(504, 201) 무시.
NSLog(@"기기등록 error %@", error);
}
}];
}
3) 푸시 메세지 수신 시 메세지 오픈/읽음 처리
//메세지 오픈 및 읽음 처리
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
//메세지 읽음 처리
finger.sharedData().requestPushCheck(withBlock: userInfo , { (posts, error) -> Void in
if error != nil{
print("check : \(posts)")
} else {
print("check error : \(error)")
}
})
completionHandler()
}
//메세지 오픈 및 읽음 처리
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
//메세지 읽음 처리
[[finger sharedData] requestPushCheckWithBlock:userInfo :^(NSString *posts, NSError *error) {
if (!error) {
NSLog(@"check : %@", posts);
}else{
NSLog(@"check error %@", error);
}
)];
completionHandler();
}
4) 푸시 수신 데이터(Payload)
{
aps = {
alert = {
body = "안녕하세요. 핑거푸시입니다";
title = "메세지 제목입니다.";
};
badge = 0; // 뱃지 카운트
category = fp; // 메세지 카테고리
"mutable-content" = 1; // notification service extension 사용 여부(이미지와 웹 링크 추가시)
sound = default; // 사운드
};
커스텀 데이터 키1 = 커스텀 데이터 값1;
커스텀 데이터 키2 = 커스텀 데이터 값2;
커스텀 데이터 키3 = 커스텀 데이터 값3;
code = "CD:1;IM:1;WL:1;PT:STOS";
// ( CD : 커스텀 데이터 여부(0 : 없음, 1 : 있음), IM : 이미지 첨부 여부(0 : 없음, 1 : 있음), WL : 웹 링크 여부(0 : 없음, 1 : 있음), PT : 메세지 타입(DEFT:일반푸시, STOS:Server to Server, LNGT:롱푸시))
imgUrl = "http://..."; // 이미지 URL
labelCode = ""; // 라벨 코드
msgTag = ...; // 메세지 고유 번호
weblink = "http://www.google.com"; // 웹 링크
}
API 연동 결과 코드
Error.code 로 SDK 내부 오류 또는 서버 오류 여부를 확인할 수 있습니다.
900 : SDK 내부 에러 코드
901 : 핑거푸시 서버 에러 코드
코드
내용
비고
200
정상 처리
403
App_key, secret 오류, 권한 없음
404
조회 대상 없음, 조회 결과 없음
500
처리 중 에러
503
필수 값 없음
504
이미 등록된 토큰
디바이스 등록에서만 사용
iOS 10 Rich Notification
Xcode 14.1 버전 기반으로 설명하고 있습니다.
iOS용 핑거푸시 SDK를 다운로드 하신 후 Sample 소스를 참고하시기 바랍니다.
Notification Service Extension 생성
1) 기존 앱에 새 타겟(Notification Service Extension)을 추가합니다.
2) 새 타겟의 옵션을 각자에 맞게 설정합니다.
애플 개발자 사이트에서 Notification Service Extension 만의 App ID와 Provisioning Profiles을 생성해줘야 합니다.
Embed In Application 설정은 Xcode의 TAGETS/General/Embedded Binaries에서 수정이 가능합니다.
3) 생성된 NotificationService에서 'fingerNotificationService' 클래스를 적용합니다.
/*Rich Notification*/
class NotificationService: fingerNotificationService {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.disableSyncBadge()
super.didReceive(request, withContentHandler: contentHandler)
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
super .serviceExtensionTimeWillExpire()
}
}
//NotificationService.h
#import <UserNotifications/UserNotifications.h>
#import "fingerNotificationService.h"
@interface NotificationService : fingerNotificationService
@end
//NotificationService.m
@interface NotificationService ()
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
[self disableSyncBadge];
[super didReceiveNotificationRequest:request withContentHandler:contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
[super serviceExtensionTimeWillExpire];
}
@end
Rich Notification 발송
핑거푸시 사용자 콘솔에서 이미지 혹은 웹링크를 넣어 보내면 Rich Notification 형식으로 푸시를 발송합니다.