//기기등록
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);
}
}];
}
//메세지 오픈 및 읽음 처리
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();
}
{
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"; // 웹 링크
}
/*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