メインコンテンツまでスキップ

通知

プッシュ通知とアプリ内通知を構成します。

注意

SDKに含まれているすべてのパブリックAPIは、Helpshift installWithPlatformId APIを介してSDKを初期化した後に呼び出す必要があります

Helpshiftを介したプッシュ通知を構成する

ユーザーから提出された問題に返信したタイミングで、ユーザーに通知を送信することができます。iOSで期待されるプッシュ通知の動作に加えて、通知をカスタマイズし、通知の受信時にアプリアイコンに数字が記載されたバッジを表示したり、音声アラートを再生したりすることができます。

アプリでまだプッシュ機能を使用していない場合には、アプリのプッシュ機能を有効にする必要があります。アプリケーションでプッシュ通知を有効にするには、AppDelegateのapplication:didFinishLaunchingWithOptions:メソッドにAPNs登録コードを追加する必要があります。

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
completionHandler:^(BOOL granted, NSError *_Nullable error) {
...
}];
[UIApplication sharedApplication registerForRemoteNotifications];
...
}

Configure Helpshift's push notification service in the Helpshift admin interface

To enable the Helpshift system to send push notifications to your users you will have to add iOS as a platform in your app (if you have not added already). And then click on the push notifications option.

Add-platform.png

In order to send push notifications to all iOS mobile apps and games, you need to establish an authenticated connection with the Apple Push Notification Servers (APNs). There are two methods you can use to authenticate:

  1. The newer token-based method (.p8)
  2. The older certificate-based method (.p12)

Token-based method (.p8)

The token-based method is faster because it offers a stateless way to communicate with APNs. It doesn't require APNs to look up the certificate or any other information related to the provider server.

We now support the newer token-based .p8 key method, which allows you to send notifications to all your iOS apps and games using a single key. You can generate your .p8 key through your Apple developer account, as explained here.

p8-configure.png

Here are the steps to configure iOS push notifications using .p8 keys:

  1. Go to Settings, then navigate to the APP SETTINGS section to choose the app you want to configure.

  2. On the App settings page, click on the CONFIGURE option next to In-app SDK.

  3. On the In-app SDK Configuration page, navigate to the Push Notification section.

  4. Enable the toggle for Apple Push Notification Service if not enabled. The app selects the p8 key authentication type by default when you enable the toggle for the first time.

  5. Upload the p8 key and fill in all the required details.

  6. Select the APNs push mode (Development/Production).

  7. Click on Save & Publish to save the changes.

Note
You can also switch from .p8 key to .p12 certificate method if required, by selecting .p12 in Authentication type and filling the details.

Certificate-based method (.p12)

You need to generate certificates for APNS on Apple's portal that you can later provide to Helpshift. This lets Helpshift send push notifications to your users. Apple has moved away from old type of certificates to Apple Push Notification service SSL. There is another option to create Apple Push Notification Authentication Key, but Helpshift does not support this option yet. It's also possible that you still have the old type of certificate that has not yet expired, this is also supported by Helpshift.

Apple provides two variations of Apple Push Notification service SSL

  • Apple Push Notification service SSL (Sandbox)
  • Apple Push Notification service SSL (Sandbox & Production)

After creating your certificate, download it. Double click on it to import it to the Keychain Access application. In the Keychain Access application, right click on the certificate that was just added, and click export it in .p12 format. Please provide a password while exporting the certificate since we do not accept empty passwords. (Note that if your development private key is not present in Keychain Access, you will not be able to export it in .p12 format.)

After export, login and upload the .p12 file in your app in the Helpshift admin panel. Provide the same password you used while exporting to .p12 format.

Please note that you need to use the same bundle identifier in the app as the one you used to create the APNS certificate.

Add-certificate.png

You can configure whether to send a badge or not, and sound alerts if you provided custom sounds bundled with your app to handle notifications. Save it and you're all set.

Development (Sandbox) mode vs. Production mode

When you build and run your app from Xcode, it is in development (Sandbox) mode. To test push notifications from Helpshift in this mode make sure you choose 'Development Mode' while uploading either of the above two certificate types.

When you publish your app and download from App Store, your app is in Production mode. To test push notifications from Helpshift in production mode make sure you choose 'Production Mode' while uploading a certificate of 'Apple Push Notification service SSL (Sandbox & Production)' type. Sandbox mode certificate will not work on a production environment.

We do not support using the same certificate for both sandbox and production apps. In these cases we recommend you create two separate apps on our dashboard, one in 'Production mode' and the other in 'Development mode'. While testing please use the credentials of the developement mode app. When you are ready to publish, please replace the credentials with those of the production level app.

Note

Your Push Certificate has an expiry date, as indicated in the below screenshot. Helpshift will not send you a reminder when your Push Certificate expires, so please make sure that your developer keeps a tab on the expiry date to reupload the Push Certificate.

cert-expiry.png

Helpshift iOS SDKが通知を処理するように構成する

注意

プッシュ機能が構成されていない場合、Helpshift SDKはエージェント/ボットにより送信されたすべてのメッセージに対してすぐに使用可能なアプリ内通知を表示します。 registerDeviceToken APIを呼び出すのは、必ずHelpshiftダッシュボードをプッシュ通知用に構成した後にしてください。Helpshiftダッシュボードを構成せずにregisterDeviceToken APIを呼び出すと、エンドユーザーに対してアプリ内通知が表示されなくなります。

Helpshift SDKをHelpshiftのプッシュ通知サービスと連携させるには、 registerDeviceToken: API呼び出しをアプリケーションのデリゲートメソッド application:didRegisterForRemoteNotificationsWithDeviceToken:の内部で呼び出す必要があります。

アプリのデリゲートファイルでは、以下のようになります。

- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[Helpshift registerDeviceToken:deviceToken];
}

アプリがUNNotificationフレームワークを使用している場合

配信された通知に応答するには、共有されているUNUserNotificationCenterオブジェクトのためのデリゲートを実装する必要があります。デリゲートオブジェクトは、通知センターがアプリに通知情報を配信するために使用するUNUserNotificationCenterDelegateプロトコルに準拠する必要があります。

  1. アプリがフォアグラウンドにあるときに通知が届くと、UNUserNotificationCenterDelegateのuserNotificationCenter:willPresentNotification:withCompletionHandler:が呼び出されます。
  2. アプリがバックグラウンドにあるか、または実行されていない場合には、システムはuserNotificationCenter:willPresentNotification:withCompletionHandler:メソッドを呼び出しません。そのような場合には、システムは通知そのものに含まれている情報に従ってユーザーにアラートを発します。 ユーザーが通知インターフェースからアクションを選択すると、システムはユーザーの選択をアプリに通知します。レスポンスを受け取るためには、デリゲートオブジェクトはuserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:メソッドを実装する必要があります。

上記のすべての場合において、通知のオリジンが「Helpshift」であれば通知辞書の「origin」フィールドをチェックし、handleNotificationWithUserInfoDictionary:isAppLaunch: APIを呼び出す必要があります。Helpshift SDKは通知を受信した問題を確認し、それらの問題の会話画面を自動的に起動します。isAppLaunchブール値フラグは、ここではアクティブまたはバックグラウンドにあるアプリと、ユーザにより強制終了されたアプリを区別するために使用されます。後者の場合、このフラグはtrueに設定されているはずです。

使用方法のサンプル

userNotificationCenter:willPresentNotification:withCompletionHandler:デリゲートの場合:

- (void) userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
if([[notification.request.content.userInfo objectForKey:@"origin"] isEqualToString:@"helpshift"]) {
[Helpshift handleNotificationWithUserInfoDictionary:notification.request.content.userInfo
isAppLaunch:false];
completionHandler(UNNotificationPresentationOptionNone);
} else {
// Handling for non-helpshift push notifications received when app is in foreground
}
}

userNotificationCenter:didReceiveNotificationResponse:withCompletionHandlerデリゲートの場合:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
if([[response.notification.request.content.userInfo objectForKey:@"origin"] isEqualToString:@"helpshift"]) {
[Helpshift handleNotificationWithUserInfoDictionary:response.notification.request.content.userInfo
isAppLaunch:YES];
} else {
// Handling for non-helpshift push notifications received when app is in background or killed
}
completionHandler();
}

バッジの数

アプリケーションアイコンでバッジのリセットを処理する必要がある場合は、 applicationDidBecomeActive:デリゲート メソッドで以下のように処理します。

- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
注意
  • すでに本番稼動中のアプリのプッシュ通知をテストする場合は、こちらをご参照ください。
  • オリジンを確認し、コールバックを受け取ったらすぐにhandleRemoteNotficationを呼び出す必要があります。SDKはアプリの状態(アクティブ/非アクティブ)を確認し、それに基づいてチャット画面を表示するか、またはアプリ内通知を表示するかを決定します。handleRemoteNotificationの呼び出しが遅れると、SDKが不正確なアプリケーションの状態を取得してしまう可能性があります。
  • アプリのビルドとデプロイにXcode 11を利用している場合には、弊社のトラブルシューティングガイドをご参照ください。

アプリ内通知

アプリ内通知は、Appleのプッシュ通知バナーに似ています。プッシュ通知とは異なり、ユーザーの使用中にアプリ内に表示されます。

これらの通知は、エージェントが顧客の問題に返信したタイミングで送信されます。顧客は、それらのバナーをクリックすることで直接会話画面に移動することができます。

In-app-notification.png

アプリ内通知を構成する

Helpshiftのインストール呼び出しは、SDKの動作を構成するためのフラグをサポートしています。 現時点では、enableInAppNotificationという1つのフラグをサポートしています。

アプリ内通知の有効化/無効化

フラグenableInAppNotification
YES/NO
デフォルトYES

Helpshift SDKが提供するアプリ内通知サポートが不要な場合には、 このフラグをNOに設定してください。この フラグの規定値はYESであり、この場合にはアプリ内通知が有効化されます。
アプリ内通知の詳細については、通知セクションをご参照ください。

例:

NSDictionary *config = @{ @"enableInAppNotification": @YES };
[Helpshift installWithPlatformId:@"YOUR_PLATFORM_ID"
domain:(NSString *)domain
config:@"YOUR_DOMAIN" config:config];

アプリ内通知の一時停止

アプリ内通知を有効にしている場合には、pauseDisplayOfInAppNotification APIを使用して通知の一時停止や再開を行います。このメソッドにYESが渡されると、アプリ内通知が発生しても表示は一時停止されます。NOを渡すと、アプリ内通知が表示されるようになります。

例:

[Helpshift pauseDisplayOfInAppNotification:YES]; // To temporarily pause in-app notifications
[Helpshift pauseDisplayOfInAppNotification:NO]; // To resume showing the in-app notifications

通知バッジ

ユーザーが投稿した 問題に対する返信に関する通知を表示する場合、 Helpshift SDKが提供する通知カウント機能を使用することで未読メッセージの総数を取得し、バッジとして 表示することができます。.hファイルと.m ファイルのそれぞれにHelpshiftDelegateを 実装することにより、通知数を非同期で取得することができます。通知は通常、ユーザーがヘルプセクションを呼び出した アプリ内でバッジとして 表示されます。これらのバッジはアプリのインターフェースのあらゆる場所に表示することが可能であり、あなたからの 未読の返信やメッセージがあることをユーザーに伝えることができます。たとえば、 以下を使用して通知のポーリングを行っている間に、 ビュー(textLabelを設定できるyourViewとします)にバッジを表示します。

[Helpshift requestUnreadMessageCount:YES];

通知数デリゲートメソッドでは、以下のように実装することができます。

- (void) handleHelpshiftEvent:(NSString *)eventName withData:(NSDictionary *)data {
...
if([eventName isEqualToString:HelpshiftEventNameReceivedUnreadMessageCount]) {
int count = [data[HelpshiftEventDataUnreadMessageCount] intValue];
BOOL fromCache = [data[HelpshiftEventDataUnreadMessageCountIsFromCache] boolValue];
NSLog(@"Unread count: %d", count);
NSLog(@"Is unreadCount served from local cache : %d", fromCache);

dispatch_async(dispatch_get_main_queue(), ^{
[yourView setTextLabel:[NSString stringWithFormat:@"%d",count];
});
}
}

同様に、通知数デリゲートメソッドのUITabBarItemについては、以下のように 実装することができます。

- (void) handleHelpshiftEvent:(NSString *)eventName withData:(NSDictionary *)data {
...
if([eventName isEqualToString:HelpshiftEventNameReceivedUnreadMessageCount]) {
int count = [data[HelpshiftEventDataUnreadMessageCount] intValue];
BOOL fromCache = [data[HelpshiftEventDataUnreadMessageCountIsFromCache] boolValue];
NSLog(@"Unread count: %d", count);
NSLog(@"Is unreadCount served from local cache : %d", fromCache);

dispatch_async(dispatch_get_main_queue(), ^{
tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",count];
});
}
}

これらは、デリゲートメソッドに新しい通知 が届くたびにビューまたはUITabBarItemを更新します。状況は、 アプリのUIにより異なります。適切な場所に通知の数を表示することにより、ユーザーの注意を 引き付けてより積極的に会話 に参加してもらえるようになる可能性があります。ローカルに保存されている未読メッセージの通知 数をユーザーに対して表示するには、requestUnreadMessageCountを呼び出します。

[Helpshift requestUnreadMessageCount:NO]

ローカルに保存されている未読メッセージの数を取得し、上記の例で説明されているものと同じように未読の数を表示します。

注意

SDKがアプリに未読の数を通知する仕組みの詳細については、未読メッセージ数イベントをご参照ください。