개발자 가이드
User GuideDeveloper GuideAPI Guide🏠
English
English
  • 홈
  • 공통
    • Unified ID Linkage Scenario
    • Constant
    • FAQ
  • 플랫폼 별 가이드
    • Android
      • Link up
      • Event
      • Set User Identification Information
      • User Profile Settings
      • Action
        • Push
        • In-app messages
        • Notification Talk
        • Message
      • Privacy Policy
        • Support for Privacy Protection
        • Preparing for data disclosure requirements on Google Play
      • Release Notes
    • iOS
      • Link up
      • Event
      • Set user identification information
      • User Profile Settings
      • Action
        • Push
        • In-app messages
        • Notification Talk
        • message
      • Release Notes
    • HybridApp
      • Link up
    • Web
      • Link up
      • Event
      • Set user identification information
      • User Profile Settings
      • Action
        • In-app messages
        • Notification Talk
        • Message
      • Advanced use cases
        • Additional Settings
      • Release Notes
Powered by GitBook
On this page
  • Before you start
  • Example Code
  1. 플랫폼 별 가이드
  2. iOS
  3. Action

Push

PreviousActionNextIn-app messages

Last updated 3 months ago

Before you start

You must first consent to receive channel notifications for the action you wish to use through

To use push messages, please register the .p8 APNs authentication key issued by Apple in . You can register it in the console's Additional Settings / Channel Additional Settings / Push / iOS Settings Management.

SDK Integration

Add the push token registration code to the AppDelegate class.

import UIKit
import UserNotifications

import DfinerySDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ...
        ...
        application.registerForRemoteNotifications()
        ...
        ...
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        
        Dfinery.shared().set(pushToken: deviceToken)

    }

}
#import <UIKit/UIKit.h>
#import <DfinerySDK/DfinerySDK.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [application registerForRemoteNotifications];
    ...
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [[Dfinery shared] setPushToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"Failed to register for remote notifications: %@", error);
}

@end

You must obtain user permission to use push messages.

Example Code

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, sound]) { granted, err in
   if granted {
       DispatchQueue.main.async {
           UIApplication.shared.registerForRemoteNotifications()
       }
   }
}
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound)
    completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
        }
    }
];

Push handling

For push handling, please adopt the UNUserNotificationCenterDelegate protocol in your AppDelegate class and integrate the SDK code.

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ...
        ...
        UNUserNotificationCenter.current().delegate = self
        ...
        ...
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        
        if Dfinery.shared().canHandleNotification(response: response) {
            completionHandler()
            return
        }
        
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

        if Dfinery.shared().canHandleForeground(notification, completionHandler: completionHandler) {
            return
        }
        
    }
}

AppDelegate.h

#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>

AppDelegate.m


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    ...
    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
    ...
    ...
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
    if ([[Dfinery shared] canHandleNotificationWithResponse:response]) {
        completionHandler();
        return;
    }
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
    if ([[Dfinery shared] canHandleForeground:notification completionHandler:completionHandler]) {
        return;
    }
}

Service Extension

To use images and buttons in DFINERY Push, you must additionally create a Notification Service Extension and integrate DfineryServiceExtension.

import UserNotifications

import DfinerySDKServiceExtension

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
        
        if let bestAttemptContent = bestAttemptContent {
            
            if DfineryServiceExtension.canHandle(content: bestAttemptContent, contentHandler: contentHandler) {
                return
            }
            
            contentHandler(bestAttemptContent)
        }
    }
    ...
}
#import "NotificationService.h"
#import <DfinerySDKServiceExtension/DfinerySDKServiceExtension.h>
...
...
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    if (self.bestAttemptContent) {
        if ([DfineryServiceExtension canHandleWithContent:self.bestAttemptContent contentHandler:contentHandler]) {
            return;
        }
    }
    
    self.contentHandler(self.bestAttemptContent);
}
...
your user profile settings.
the DFINERY console