Service | Cocoapods Pod Name | Framework | Dependency | Build Settings |
---|---|---|---|---|
Push | NHNCloudPush | NHNCloudPush.framework | UserNotifications.framework [NHNCloudVoIP] PushKit.framework CallKit.framework |
|
Mandatory | NHNCloudCore NHNCloudCommon |
NHNCloudCore.framework NHNCloudCommon.framework |
OTHER_LDFLAGS = ( "-ObjC", "-lc++" ); |
platform :ios, '11.0'
use_frameworks!
target '{YOUR PROJECT TARGET NAME}' do
pod 'NHNCloudPush'
end
If a user ID is not set at the time of initial token registration, it is registered using the device identifier.
(Refer to the token registration section)Setting or changing the user ID after token registration will update token information.
// Service login, set the user ID
[NHNCloudSDK setUserID:@"INPUT_USER_ID"];
Even if logout occurs, the registered token is not deleted.
// Service logout, set the user ID to nil
[NHNCloudSDK setUserID:nil];
The token registration and query features cannot be used without initialization.
// Initialize and set Delegate
+ (void)initWithConfiguration:(NHNCloudPushConfiguration *)configuration
delegate:(nullable id<NHNCloudPushDelegate>)delegate;
// Initialize
+ (void)initWithConfiguration:(NHNCloudPushConfiguration *)configuration;
// Set Delegate
+ (void)setDelegate:(nullable id<NHNCloudPushDelegate>)delegate;
It is recommended to set Delegate in application:didFinishLaunchingWithOptions: function for smooth message reception.
@protocol NHNCloudPushDelegate <NSObject>
@optional
// Receive a message
- (void)didReceiveNotificationWithMessage:(NHNCloudPushMessage *)message;
// Execute notification (click)
- (void)didReceiveNotificationResponseWithMessage:(NHNCloudPushMessage *)message
// Execute notification action (button)
- (void)didReceiveNotificationAction:(NHNCloudPushNotificationAction *)action
@end
#import <NHNCloudPush/NHNCloudPush.h>
@interface AppDelegate () <UIApplicationDelegate, NHNCloudPushDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// Create a configuration object.
NHNCloudPushConfiguration *configuration = [[NHNCloudPushConfiguration alloc] initWithAppKey:@"INPUT_YOUR_APPKEY"];
#if DEBUG
// In the development environment (DEBUG), the sandbox property below must be set to YES to receive the message sent using the development certificate.
configuration.sandbox = YES;
#endif
// If you want to register the token even if you don't get permission to allow notifications, you should change the value of the alwaysAllowTokenRegistration property to YES. The default value is NO.
configuration.alwaysAllowTokenRegistration = NO;
// Set Delegate in tandem with the initialization.
[NHNCloudPush initWithConfiguration:configuration
delegate:self];
return YES;
}
#pragma mark - NHNCloudPushDelegate
// Receive a message
- (void)didReceiveNotificationWithMessage:(NHNCloudPushMessage *)message {
// ...
}
// Notification response (execute)
- (void)didReceiveNotificationResponseWithMessage:(NHNCloudPushMessage *)message {
// ...
}
// Execute notification action (button, reply)
- (void)didReceiveNotificationAction:(NHNCloudPushNotificationAction *)action {
// ...
}
Option Name | Description | Default |
---|---|---|
foregroundEnabled | Whether to show notifications when the app is in the foreground state | NO |
badgeEnabled | Whether to use a badge icon | YES |
soundEnabled | Whether to use a notification sound | YES |
+ (void)setNotificationOptions:(nullable NHNCloudNotificationOptions *)options;
NHNCloudNotificationOptions *options = [[NHNCloudNotificationOptions alloc] init];
options.foregroundEnabled = YES; // Set the use of foreground notification (default : NO)
options.badgeEnabled = YES; // Set the use of badge icon (default : YES)
options.soundEnabled = YES; // Set the use of notification sound (default : YES)
[NHNCloudPush setNotificationOptions:options];
// Token registration and agreement setting
+ (void)registerWithAgreement:(NHNCloudPushAgreement *)agreement
completionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
// Register a token using the previously set agreement information
+ (void)registerWithCompletionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
NHNCloudPushAgreement *agreement = [[NHNCloudPushAgreement alloc] initWithAllowNotifications:YES]; // Agree to receive notification message
agreement.allowAdvertisements = YES; // Agree to receive advertising notification message
agreement.allowNightAdvertisements = YES; // Agree to receive night-time advertising notification message
[NHNCloudPush registerWithAgreement:agreement
completionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// Token registration succeeded
NSLog(@"Successfully registered : %@", tokenInfo.deviceToken);
} else {
// Token registration failed
NSLog(@"Failed to register : %@", error.localizedDescription);
}
}];
+ (void)queryTokenInfoWithCompletionHandler:(void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
[NHNCloudPush queryTokenInfoWithCompletionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// Token information query succeeded
NSLog(@"Successfully query token info : %@", [tokenInfo description]);
} else {
// Token information query failed
NSLog(@"Failed to query token info : %@", error.localizedDescription);
}
}];
If you do not want to receive messages after the service logout, you must unregister the token.
Even if the token is unregistered, the notification permission on the device is not revoked.
+ (void)unregisterWithCompletionHandler:(nullable void (^)(NSString * _Nullable deviceToken, NSError * _Nullable error))completionHandler;
[NHNCloudPush unregisterWithCompletionHandler:^(NSString *deviceToken, NSError *error) {
if (error == nil) {
// Token unregistration succeeded
NSLog(@"Successfully unregistered token : %@", deviceToken);
} else {
// Token unregistration failed
NSLog(@"Failed to unregister : %@", error.localizedDescription);
}
}];
Rich message reception is supported in iOS 10.0+ or higher.
Type | Feature | Action |
---|---|---|
Open App (OPEN_APP) | Run the application | NHNCloudPushNotificationActionOpenApp |
Open URL (OPEN_URL) | Go to URL (run Web URL address or app's custom scheme) |
NHNCloudPushNotificationActionOpenURL |
Reply (REPLY) | Send a reply from notification | NHNCloudPushNotificationActionReply |
Cancel (DISMISS) | Cancel the current notification | NHNCloudPushNotificationActionDismiss |
Up to 3 buttons per message are supported.
Type | Supported formats | Maximum size | Recommendations |
---|---|---|---|
Image | JPEG, PNG, GIF | 10 MB | Landscape image is recommended Max size: 1038 x 1038 |
Video | MPEG, MPEG3Video, MPEG4, AVIMovie | 50 MB | |
Sound | WaveAudio, MP3, MPEG4Audio | 5 MB |
When a web URL is used, it takes time to download media files.
To collect metrics, an Appkey must be defined in Push SDK initialization or info.plist file.
Received metrics collection is supported in iOS 10.0+ or higher.
@implementation NotificationService
- (instancetype)init {
self = [super init];
if (self) {
// Only AppKey needs to be set, because it is used only for sending metrics.
NHNCloudPushConfiguration *configuration = [[NHNCloudPushConfiguration alloc] initWithAppKey:@"INPUT_YOUR_APPKEY"];
[NHNCloudPush initWithConfiguration:configuration];
}
return self;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<key>NHNCloudSDK</key>
<dict>
<key>NHNCloudPush</key>
<dict>
<key>AppKey</key>
<string>[INPUT_YOUR_APPKEY]</string>
</dict>
</dict>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<key>NHNCloudSDK</key>
<dict>
<key>NHNCloudPush</key>
<dict>
<key>AppKey</key>
<string>[INPUT_YOUR_APPKEY]</string>
</dict>
</dict>
This is supported from iOS 10.0+.
#import <UserNotifications/UserNotifications.h>
#import <NHNCloudPush/NHNCloudPush.h>
@interface NotificationService : NHNCloudPushServiceExtension
@end
// Add the tag ID list of the user ID
+ (void)addUserTagWithIdentifiers:(NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// Update the tag ID list of the user ID
+ (void)setUserTagWithIdentifiers:(nullable NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSError * _Nullable error))completionHandler;
// Acquire the tag ID list of the user ID
+ (void)getUserTagWithCompletionHandler:(void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// Delete the tag ID list of the user ID
+ (void)removeUserTagWithIdentifiers:(NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// Delete all tags of the user ID
+ (void)removeAllUserTagWithCompletionHandler:(nullable void (^)(NSError * _Nullable error))completionHandler;
// Create a tag ID list to add
NSMutableSet<NSString *> *tagIDs = [NSMutableSet set];
[tagIDs addObject:TAG_ID_1]; // e.g. "ZZPP00b6" (8-character string)
[tagIDs addObject:TAG_ID_2];
// Add the tag ID list of the logged-in user ID
[NHNCloudPush addUserTagWithIdentifiers:tagIDs
completionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// Adding the tag ID list succeeded
} else {
// Adding the tag ID list failed
}
}];
// Update the tag ID list of the logged-in user ID (Existing tag ID list is deleted and set to the inputted value)
[NHNCloudPush setUserTagWithIdentifiers:tagIDs
completionHandler:^(NSError *error) {
if (error == nil) {
// Updating the tag ID list succeeded
} else {
// Updating the tag ID list failed
}
}];
// Returns the whole tag ID list of the logged-in user ID
[NHNCloudPush getUserTagWithCompletionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// Tag ID list retrieval succeeded
} else {
// Tag ID list retrieval failed
}
}];
// Create a tag ID list to delete
NSMutableSet<NSString *> *tagIDs = [NSMutableSet set];
[tagIDs addObject:TAG_ID_1]; // e.g. "ZZPP00b6" (8-character string)
[tagIDs addObject:TAG_ID_2];
// Delete the tag ID list of the logged-in user ID
[NHNCloudPush removeUserTagWithIdentifiers:tagIDs
completionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// Deleting the tag ID list succeeded
} else {
// Deleting the tag ID list failed
}
}];
// Delete the whole tag ID list of the logged-in user ID
[NHNCloudPush removeAllUserTagWithCompletionHandler:^(NSError *error) {
if (error == nil) {
// Deleting the whole user tag succeeded
} else {
// Deleting the whole user tag failed
}
}];
VoIP function is supported from iOS 10.0 or higher.
Project Target > Signing & Capabilities > + Capability > Background Modes
Voice over IP must be enabled.
It is recommended to set Delegate in application:didFinishLaunchingWithOptions: function for smooth message reception.
@protocol NHNCloudVoIPDelegate <NSObject>
// Receive a message
- (void)didReceiveIncomingVoiceCallWithMessage:(NHNCloudPushMessage *)message;
@end
// Add the VoIP submodule.
#import <NHNCloudPush/NHNCloudVoIP.h>
@interface AppDelegate () <UIApplicationDelegate, NHNCloudVoIPDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// Set Delegate.
[NHNCloudVoIP setDelegate:self];
return YES;
}
#pragma mark - NHNCloudVoIPDelegate
// Receive a message
- (void)didReceiveIncomingVoiceCallWithMessage:(NHNCloudPushMessage *)message {
// ...
}
+ (void)registerWithCompletionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
[NHNCloudVoIP registerWithCompletionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// Token registration succeeded
NSLog(@"Successfully registered : %@", tokenInfo.deviceToken);
} else {
// Token registration failed
NSLog(@"Failed to register : %@", error.localizedDescription);
}
}];
@interface NHNCloudVoIP : NSObject
+ (void)queryTokenInfoWithCompletionHandler:(void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
[NHNCloudVoIP queryTokenInfoWithCompletionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// Token information query succeeded
NSLog(@"Successfully query token info : %@", [tokenInfo description]);
} else {
// Token information query failed
NSLog(@"Failed to query token info : %@", error.localizedDescription);
}
}];
If you do not want to receive messages after the service logout, you must unregister the token.
+ (void)unregisterWithCompletionHandler:(nullable void (^)(NSString * _Nullable deviceToken, NSError * _Nullable error))completionHandler;
[NHNCloudVoIP unregisterWithCompletionHandler:^(NSString *deviceToken, NSError *error) {
if (error == nil) {
// Token unregistration succeeded
NSLog(@"Successfully unregistered token : %@", deviceToken);
} else {
// Token unregistration failed
NSLog(@"Failed to unregister : %@", error.localizedDescription);
}
}];
extern NSErrorDomain const NHNCloudPushErrorDomain;
typedef NS_ERROR_ENUM(NHNCloudPushErrorDomain, NHNCloudPushError) {
NHNCloudPushErrorUnknown = 0, // Unknown
NHNCloudPushErrorNotInitialized = 1, // Not initialized
NHNCloudPushErrorUserInvalid = 2, // User ID unset
NHNCloudPushErrorPermissionDenied = 3, // Failed to obtain permission
NHNCloudPushErrorSystemFailed = 4, // Failure by the system
NHNCloudPushErrorTokenInvalid = 5, // Token value unavailable or invalid
NHNCloudPushErrorAlreadyInProgress = 6, // Already in progress
NHNCloudPushErrorParameterInvalid = 7, // Parameter error
NHNCloudPushErrorNotSupported = 8, // Unsupported feature
};
extern NSErrorDomain const NHNCloudNHNCloudHttpErrorDomain;
typedef NS_ERROR_ENUM(NHNCloudHttpErrorDomain, NHNCloudHttpError) {
NHNCloudHttpErrorNetworkNotAvailable = 100, // Network unavailable
NHNCloudHttpErrorRequestFailed = 101, // HTTP status code is not 200, or the server could not read the request properly
NHNCloudHttpErrorRequestTimeout = 102, // Timeout
NHNCloudHttpErrorRequestInvalid = 103, // Invalid request (parameter error, etc.)
NHNCloudHttpErrorURLInvalid = 104, // URL error
NHNCloudHttpErrorResponseInvalid = 105, // Server response error
NHNCloudHttpErrorAlreadyInprogress = 106, // Same request is already in progress
NHNCloudHttpErrorRequiresSecureConnection = 107, // Allow Arbitrary Loads unset
};
@interface NHNCloudPushConfiguration : NSObject
// Service AppKey
@property (nonatomic, copy, readonly) NSString *appKey;
// Service zone
@property (nonatomic) NHNCloudServiceZone serviceZone;
// Country code (the country code used as a basis time for sending reserved messages)
@property (nonatomic, copy) NSString *countryCode;
// Language code (criteria for language selection when sending multi-language messages)
@property (nonatomic, copy) NSString *languageCode;
// Timezone
@property (nonatomic, copy) NSString *timezone;
// Sandbox (Debug) environment setting
@property (nonatomic) BOOL sandbox;
// Whether to register a token if a user denies permission to allow notifications
@property (nonatomic) BOOL alwaysAllowTokenRegistration;
+ (instancetype)configurationWithAppKey:(NSString *)appKey;
- (instancetype)initWithAppKey:(NSString *)appKey;
@end
@interface NHNCloudNotificationOptions : NSObject
// Whether to expose the notification when the app is running
@property (nonatomic) BOOL foregroundEnabled;
// Whether to use a badge icon
@property (nonatomic) BOOL badgeEnabled;
// Whether to use notification sound
@property (nonatomic) BOOL soundEnabled;
@end
@interface NHNCloudPushAgreement : NSObject
// Whether to agree to show notification
@property (nonatomic, assign) BOOL allowNotifications;
// Whether to agree to show advertising notification
@property (nonatomic, assign) BOOL allowAdvertisements;
// Whether to agree to show night-time advertising notification
@property (nonatomic, assign) BOOL allowNightAdvertisements;
+ (instancetype)agreementWithAllowNotifications:(BOOL)allowNotifications;
* (instancetype)initWithAllowNotifications:(BOOL)allowNotifications;
@end
@interface NHNCloudPushMessage : NSObject
@property (nonatomic, readonly) NSString *identifier;
@property (nonatomic, readonly, nullable) NSString *title;
@property (nonatomic, readonly, nullable) NSString *body;
@property (nonatomic, readonly) NSInteger badge;
@property (nonatomic, readonly, nullable) NHNCloudPushRichMessage *richMessage;
@property (nonatomic, readonly) NSDictionary<NSString *, NSString *> *payload;
@end
@interface NHNCloudPushRichMessage : NSObject
@property (nonatomic, readonly, nullable) NHNCloudPushMedia *media;
@property (nonatomic, readonly, nullable) NSArray<NHNCloudPushButton *> *buttons;
@end
@interface NHNCloudPushMedia : NSObject
@property (nonatomic, readonly) NHNCloudPushMediaType mediaType;
@property (nonatomic, readonly) NSString *source;
@end
@interface NHNCloudPushButton : NSObject
@property (nonatomic, readonly) NSString *identifier;
@property (nonatomic, readonly) NHNCloudPushButtonType buttonType;
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly, nullable) NSString *link;
@property (nonatomic, readonly, nullable) NSString *hint;
@property (nonatomic, readonly, nullable) NSString *submit;
@end
typedef NS_ENUM(NSInteger, NHNCloudPushNotificationActionType) {
NHNCloudPushNotificationActionDismiss = 0,
NHNCloudPushNotificationActionOpenApp = 1,
NHNCloudPushNotificationActionOpenURL = 2,
NHNCloudPushNotificationActionReply = 3,
};
@interface NHNCloudPushNotificationAction : NSObject <NSCoding, NSCopying>
@property (nonatomic, readonly) NSString *actionIdentifier;
@property (nonatomic, readonly) NSString *categoryIdentifier;
@property (nonatomic, readonly) NHNCloudPushNotificationActionType actionType;
@property (nonatomic, readonly) NHNCloudPushButton *button;
@property (nonatomic, readonly) NHNCloudPushMessage *message;
@property (nonatomic, readonly, nullable) NSString *userText;
@end
typedef NSString *NHNCloudPushType NS_STRING_ENUM;
// APNS type
extern NHNCloudPushType const NHNCloudPushTypeAPNS;
// VoIP type
extern NHNCloudPushType const NHNCloudPushTypeVoIP;
@interface NHNCloudPushTokenInfo : NSObject
// User ID
@property (nonatomic, readonly) NSString *userID;
// Token
@property (nonatomic, readonly) NSString *deviceToken;
// Country code
@property (nonatomic, readonly) NSString *countryCode;
// Language setting
@property (nonatomic, readonly) NSString *languageCode;
// Push token type
@property (nonatomic, readonly) NHNCloudPushType pushType;
// Whether to agree to show notification
@property (nonatomic, readonly) BOOL allowNotifications;
// Whether to agree to show advertising notification
@property (nonatomic, readonly) BOOL allowAdvertisements;
// Whether to agree to show night-time advertising notification
@property (nonatomic, readonly) BOOL allowNightAdvertisements;
// Timezone
@property (nonatomic, readonly) NSString *timezone;
// Token update time
@property (nonatomic, readonly) NSString *updateDateTime;
// Whether the token is registered in the sandbox environment
@property (nonatomic, getter=isSandbox) BOOL sandbox;
@end