Service | Cocoapods Pod Name | Framework | Dependency | Build Settings |
---|---|---|---|---|
NHN Cloud 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
初回トークン登録時に、ユーザーIDが設定されていない場合は、デバイス識別子を使用して登録します。
(トークン登録セクション参照)トークン登録後、ユーザーIDを設定、または変更すると、トークン情報を更新します。
// サービスログイン、ユーザーID設定
[NHNCloudSDK setUserID:@"INPUT_USER_ID"];
ログアウトしても登録されたトークンは削除されません。
// サービスログアウト、ユーザーIDをnilに設定
[NHNCloudSDK setUserID:nil];
初期化をしない状態では、トークン登録、および照会機能を使用できません。
開発環境では、必ずNHNCloudPushConfigurationのsandboxプロパティをYESに設定しないと、開発用認証書で送信したメッセージの受信ができません。
// 初期化、およびDelegate設定
+ (void)initWithConfiguration:(NHNCloudPushConfiguration *)configuration
delegate:(nullable id<NHNCloudPushDelegate>)delegate;
// 初期化
+ (void)initWithConfiguration:(NHNCloudPushConfiguration *)configuration;
// Delegate設定
+ (void)setDelegate:(nullable id<NHNCloudPushDelegate>)delegate;
スムーズにメッセージ受信が行えるように、application:didFinishLaunchingWithOptions: 関数でDelegate設定をお勧めいたします。
@protocol NHNCloudPushDelegate <NSObject>
@optional
// メッセージ受信
- (void)didReceiveNotificationWithMessage:(NHNCloudPushMessage *)message;
// 通知実行(クリック)
- (void)didReceiveNotificationResponseWithMessage:(NHNCloudPushMessage *)message
// 通知アクション(ボタン)実行
- (void)didReceiveNotificationAction:(NHNCloudPushNotificationAction *)action
@end
#import <NHNCloudPush/NHNCloudPush.h>
@interface AppDelegate () <UIApplicationDelegate, NHNCloudPushDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// 設定オブジェクトを作成します。
NHNCloudPushConfiguration *configuration = [[NHNCloudPushConfiguration alloc] initWithAppKey:@"INPUT_YOUR_APPKEY"];
#if DEBUG
// 開発環境(Debug)では、必ず、以下のsandboxプロパティをYESに設定しなければなりません。設定しないと、開発用認証書で送信したメッセージの受信ができなくなります。
configuration.sandbox = YES;
#endif
// 通知許可権限を取得できなくてもトークンを登録したい場合は、alwaysAllowTokenRegistrationプロパティの値をYESに変更する必要があります。
configuration.alwaysAllowTokenRegistration = NO;
// 初期化と同時に、Delegateを設定します。
[NHNCloudPush initWithConfiguration:configuration
delegate:self];
return YES;
}
#pragma mark - NHNCloudPushDelegate
// メッセージ受信
- (void)didReceiveNotificationWithMessage:(NHNCloudPushMessage *)message {
// ...
}
// 通知応答(実行)
- (void)didReceiveNotificationResponseWithMessage:(NHNCloudPushMessage *)message {
// ...
}
// 通知アクション(ボタン、返信)実行
- (void)didReceiveNotificationAction:(NHNCloudPushNotificationAction *)action {
// ...
}
オプション名 | 説明 | デフォルト値 |
---|---|---|
foregroundEnabled | アプリがフォアグラウンド状態の時に通知を表示するか | NO |
badgeEnabled | バッジアイコンを使用するか | YES |
soundEnabled | 通知音を使用するか | YES |
+ (void)setNotificationOptions:(nullable NHNCloudNotificationOptions *)options;
NHNCloudNotificationOptions *options = [[NHNCloudNotificationOptions alloc] init];
options.foregroundEnabled = YES; // フォアグラウンド通知使用設定 (default : NO)
options.badgeEnabled = YES; // バッジアイコン使用設定 (default : YES)
options.soundEnabled = YES; // 通知音使用設定(default : YES)
[NHNCloudPush setNotificationOptions:options];
// トークン登録、および受信同意設定
+ (void)registerWithAgreement:(NHNCloudPushAgreement *)agreement
completionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
// すでに設定された受信同意情報を使用してトークン登録
+ (void)registerWithCompletionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
NHNCloudPushAgreement *agreement = [[NHNCloudPushAgreement alloc] initWithAllowNotifications:YES]; // 通知メッセージの受信同意
agreement.allowAdvertisements = YES; // 広報性メッセージの受信同意
agreement.allowNightAdvertisements = YES; // 夜間広報性通知メッセージの受信同意
[NHNCloudPush registerWithAgreement:agreement
completionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// トークン登録成功
NSLog(@"Successfully registered : %@", tokenInfo.deviceToken);
} else {
// トークン登録失敗
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) {
// トークン情報照会成功
NSLog(@"Successfully query token info : %@", [tokenInfo description]);
} else {
// トークン情報照会失敗
NSLog(@"Failed to query token info : %@", error.localizedDescription);
}
}];
サービスログアウト後にメッセージの受信を希望しない場合、トークンを解除してください
トークンが解除されても端末上の通知権限は回収されません。
+ (void)unregisterWithCompletionHandler:(nullable void (^)(NSString * _Nullable deviceToken, NSError * _Nullable error))completionHandler;
[NHNCloudPush unregisterWithCompletionHandler:^(NSString *deviceToken, NSError *error) {
if (error == nil) {
// トークン解除成功
NSLog(@"Successfully unregistered token : %@", deviceToken);
} else {
// トークン解除失敗
NSLog(@"Failed to unregister : %@", error.localizedDescription);
}
}];
リッチメッセージの受信は、iOS 10.0+ 以上からサポートします。
タイプ | 機能 | アクション |
---|---|---|
アプリを開く(OPEN_APP) | アプリケーション実行 | NHNCloudPushNotificationActionOpenApp |
URLを開く(OPEN_URL) | URLに移動 (ウェブサイトのURL、またはアプリカスタムスキームを実行) |
NHNCloudPushNotificationActionOpenURL |
返信(REPLY) | 通知から返信を転送 | NHNCloudPushNotificationActionReply |
取消(DISMISS) | 現在の通知を取消 | NHNCloudtPushNotificationActionDismiss |
ボタンは、メッセージあたり最大 3つまでサポートします。
タイプ | サポートするフォーマット | 最大サイズ | 推奨事項 |
---|---|---|---|
画像 | JPEG, PNG, GIF | 10 MB | 横画像推奨 最大サイズ : 1038 x 1038 |
動画 | MPEG, MPEG3Video, MPEG4, AVIMovie | 50 MB | |
音声 | WaveAudio, MP3, MPEG4Audio | 5 MB |
ウェブURLを使用する場合は、メディアファイルのダウンロードに時間がかかります。
指標の収集のためには、Push SDKの初期化、あるいはinfo.plistファイルにAppKeyが定義されている必要があります。
受信指標の収集は、iOS 10.0+以上からサポートします。
アプリケーションとエクステンションは一緒にインストールされますが、分離した別々のサンドボックス環境であるため、アプリケーションの初期化とは別に、エスステンションでも初期化しなければなりません。
@implementation NotificationService
- (instancetype)init {
self = [super init];
if (self) {
// 指標送信にのみ使用されるため、AppKeyのみ設定してください。
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>
iOS 10.0+からサポートします。
iOSのExtensionはアプリと一緒にインストールされますが、アプリとは分離された別のサンドボックス環境であるため、コンテナを共有することはできません。
#import <UserNotifications/UserNotifications.h>
#import <NHNCloudPush/NHNCloudPush.h>
@interface NotificationService : NHNCloudPushServiceExtension
@end
// ユーザーIDのタグIDリスト追加
+ (void)addUserTagWithIdentifiers:(NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// ユーザーIDのタグIDリストアップデート
+ (void)setUserTagWithIdentifiers:(nullable NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSError * _Nullable error))completionHandler;
// ユーザーIDのタグIDリスト取得
+ (void)getUserTagWithCompletionHandler:(void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// ユーザーIDのタグIDリスト獲得
+ (void)removeUserTagWithIdentifiers:(NSSet<NSString *> *)tagIdentifiers
completionHandler:(nullable void (^)(NSSet<NSString *> * _Nullable tagIdentifiers, NSError * _Nullable error))completionHandler;
// ユーザーIDの全タグ削除
+ (void)removeAllUserTagWithCompletionHandler:(nullable void (^)(NSError * _Nullable error))completionHandler;
// 追加するタグIDリスト作成
NSMutableSet<NSString *> *tagIDs = [NSMutableSet set];
[tagIDs addObject:TAG_ID_1]; // e.g. "ZZPP00b6" (8桁の文字列)
[tagIDs addObject:TAG_ID_2];
// ログインされているユーザーIDのタグIDリスト追加
[NHNCloudPush addUserTagWithIdentifiers:tagIDs
completionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// タグIDリスト追加成功
} else {
// タグIDリスト追加失敗
}
}];
// ログインされているユーザーIDのタグIDリストアップデート(既存のタグIDリストは削除され、入力した値で設定)
[NHNCloudPush setUserTagWithIdentifiers:tagIDs
completionHandler:^(NSError *error) {
if (error == nil) {
// タグIDリストアップデート成功
} else {
// タグIDリストアップデート成功
}
}];
// ログインされているユーザーIDの全タグIDリストを返します。
[NHNCloudPush getUserTagWithCompletionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// タグIDリスト獲得成功
} else {
// タグIDリスト獲得失敗
}
}];
// 削除するタグIDリスト作成
NSMutableSet<NSString *> *tagIDs = [NSMutableSet set];
[tagIDs addObject:TAG_ID_1]; // e.g. "ZZPP00b6" (8桁の文字列)
[tagIDs addObject:TAG_ID_2];
// ログインされているユーザーIDのタグIDリスト削除
[NHNCloudPush removeUserTagWithIdentifiers:tagIDs
completionHandler:^(NSSet<NSString *> *tagIdentifiers, NSError *error) {
if (error == nil) {
// タグIDリスト削除成功
} else {
// タグIDリスト削除失敗
}
}];
// ログインされているユーザーIDの全タグIDリスト削除
[NHNCloudPush removeAllUserTagWithCompletionHandler:^(NSError *error) {
if (error == nil) {
// 全ユーザータグ削除成功
} else {
// 全ユーザータグ削除成功
}
}];
VoIP機能はiOS 10.0以上からサポートします。
Project Target > Signing & Capabilities > + Capability > Background Modes
Voice over IP項目を有効化する必要があります。
スムーズにメッセージを受信するために application:didFinishLaunchingWithOptions: 関数でDelegate設定をお勧めします。
@protocol NHNCloudVoIPDelegate <NSObject>
// メッセージ受信
- (void)didReceiveIncomingVoiceCallWithMessage:(NHNCloudPushMessage *)message;
@end
// VoIPサブモジュールを追加します。
#import <NHNCloudPush/NHNCloudVoIP.h>
@interface AppDelegate () <UIApplicationDelegate, NHNCloudVoIPDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// Delegatを設定します。
[NHNCloudVoIP setDelegate:self];
return YES;
}
#pragma mark - NHNCloudVoIPDelegate
// メッセージ受信
- (void)didReceiveIncomingVoiceCallWithMessage:(NHNCloudPushMessage *)message {
// ...
}
+ (void)registerWithCompletionHandler:(nullable void (^)(NHNCloudPushTokenInfo * _Nullable tokenInfo, NSError * _Nullable error))completionHandler;
[NHNCloudVoIP registerWithCompletionHandler:^(NHNCloudPushTokenInfo *tokenInfo, NSError *error) {
if (error == nil) {
// トークン登録成功
NSLog(@"Successfully registered : %@", tokenInfo.deviceToken);
} else {
// トークン登録失敗
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) {
// トークン情報照会成功
NSLog(@"Successfully query token info : %@", [tokenInfo description]);
} else {
// トークン情報照会失敗
NSLog(@"Failed to query token info : %@", error.localizedDescription);
}
}];
サービスログアウト後にメッセージの受信を希望されない場合、トークンを解除してください。
+ (void)unregisterWithCompletionHandler:(nullable void (^)(NSString * _Nullable deviceToken, NSError * _Nullable error))completionHandler;
[NHNCloudVoIP unregisterWithCompletionHandler:^(NSString *deviceToken, NSError *error) {
if (error == nil) {
// トークン解除成功
NSLog(@"Successfully unregistered token : %@", deviceToken);
} else {
// トークン解除失敗
NSLog(@"Failed to unregister : %@", error.localizedDescription);
}
}];
extern NSErrorDomain const NHNCloudPushErrorDomain;
typedef NS_ERROR_ENUM(NHNCloudPushErrorDomain, NHNCloudPushError) {
NHNCloudPushErrorUnknown = 0, // 不明
NHNCloudPushErrorNotInitialized = 1, // 初期化していない
NHNCloudPushErrorUserInvalid = 2, // ユーザーID未設定
NHNCloudPushErrorPermissionDenied = 3, // 権限獲得失敗
NHNCloudPushErrorSystemFailed = 4, // システムによる失敗
NHNCloudPushErrorTokenInvalid = 5, // トークン値がないか、無効
NHNCloudPushErrorAlreadyInProgress = 6, // すでに進行中
NHNCloudPushErrorParameterInvalid = 7, // 無効な変数
NHNCloudPushErrorNotSupported = 8, // サポートしていない機能
};
extern NSErrorDomain const NHNCloudHttpErrorDomain;
typedef NS_ERROR_ENUM(NHNCloudHttpErrorDomain, NHNCloudHttpError) {
NHNCloudHHttpErrorNetworkNotAvailable = 100, // ネットワーク使用不可
NHNCloudHHttpErrorRequestFailed = 101, // HTTP Status Codeが200でない、あるいはサーバーで要求を正しく読み取れない
NHNCloudHHttpErrorRequestTimeout = 102, // タイムアウト
NHNCloudHHttpErrorRequestInvalid = 103, // 誤ったリクエスト (パラメーターエラーなど)
NHNCloudHHttpErrorURLInvalid = 104, // URLエラー
NHNCloudHHttpErrorResponseInvalid = 105, // サーバー応答エラー
NHNCloudHHttpErrorAlreadyInprogress = 106, // 同一リクエストですでに実行中
NHNCloudHHttpErrorRequiresSecureConnection = 107, // Allow Arbitrary Loads未設定
};
@interface NHNCloudPushConfiguration : NSObject
// サービスAppKey
@property (nonatomic, copy, readonly) NSString *appKey;
// サービスゾーン
@property (nonatomic) NHNCloudServiceZone serviceZone;
// 国コード (予約メッセージ送信時、基準時間となる国コード)
@property (nonatomic, copy) NSString *countryCode;
// 言語コード(多言語メッセージ送信時の言語選択基準)
@property (nonatomic, copy) NSString *languageCode;
// タイムゾーン
@property (nonatomic, copy) NSString *timezone;
// Sandbox(Debug)環境設定
@property (nonatomic) BOOL sandbox;
// ユーザーが通知許可権限を拒否しても、トークンを登録するかどうか
@property (nonatomic) BOOL alwaysAllowTokenRegistration;
+ (instancetype)configurationWithAppKey:(NSString *)appKey;
- (instancetype)initWithAppKey:(NSString *)appKey;
@end
@interface NHNCloudNotificationOptions : NSObject
// アプリ実行中に通知に表示するか
@property (nonatomic) BOOL foregroundEnabled;
// バッジアイコンを使用するか
@property (nonatomic) BOOL badgeEnabled;
// 通知音を使用するか
@property (nonatomic) BOOL soundEnabled;
@end
@interface NHNCloudPushAgreement : NSObject
// 通知表示に同意するか
@property (nonatomic, assign) BOOL allowNotifications;
// 広告通知表示に同意するか
@property (nonatomic, assign) BOOL allowAdvertisements;
// 夜間広告性通知に同意するか
@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,
NHNCloudPushNotificationActionOpenURL = 2,
NHNCloudPushNotificationActionOpenApp = 1,
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タイプ
extern NHNCloudPushType const NHNCloudPushTypeAPNS;
// VoIPタイプ
extern NHNCloudPushType const NHNCloudPushTypeVoIP;
@interface NHNCloudPushTokenInfo : NSObject
// ユーザーID
@property (nonatomic, readonly) NSString *userID;
// トークン
@property (nonatomic, readonly) NSString *deviceToken;
// 国コード
@property (nonatomic, readonly) NSString *countryCode;
// 言語設定
@property (nonatomic, readonly) NSString *languageCode;
// Pushトークンタイプ
@property (nonatomic, readonly) NHNCloudPushType pushType;
// 通知表示に同意するか
@property (nonatomic, readonly) BOOL allowNotifications;
// 広告通知表示に同意するか
@property (nonatomic, readonly) BOOL allowAdvertisements;
// 夜間広告性表示に同意するか
@property (nonatomic, readonly) BOOL allowNightAdvertisements;
// 標準時間帯
@property (nonatomic, readonly) NSString *timezone;
// トークンアップデート時間
@property (nonatomic, readonly) NSString *updateDateTime;
// サンドボックス環境で登録されたトークンかを確認
@property (nonatomic, getter=isSandbox) BOOL sandbox;
@end