推送通知

iOS版亚博Zendesk SDK使用Apple Push Notification service (apn)进行推送通知。以下步骤将指导您或您的开发团队在应用程序中为Zendesk SDK设置推送通知。亚博

步骤1 -在Apple Developer站点上创建。p12证书

对于下面的步骤,您必须登录到您的Apple Developer帐户。如果你还没有开发者账户,你可以注册在这里

  1. 登录Apple Developer Member Center,然后导航到证书列表
  2. 单击+按钮以创建新证书,然后选择Apple推送通知服务SSL (Sandbox & Production)
  3. 从下拉菜单中选择你的app ID,然后点击continue。
  4. 遵循指令使用Keychain Access生成证书签名请求(CSR),并将其上传以生成证书。
  5. 证书准备好后,将其下载到您的计算机并双击它以在Keychain Access中打开它。
  6. 右键单击您创建的证书,然后选择导出“Apple Push Services: {your-app-id}”
  7. 如果需要,选择一个密码,并保存.p12文件到你的电脑。

重要的:我们不支持只使用沙箱证书。为了启用推送通知,您必须在生产环境中使用证书。
我们不支持任何其他方式来生成CSR和。p12文件。
苹果在应用程序中实现推送功能所需的文档没有由Zendesk提供,但可以在Zendesk上找到亚博苹果开发者网站
这同样适用于Xcode配置的某些部分,除了添加推送通知功能(见下文)。

步骤2 -在Zendesk管理中心添加。p12证书亚博

现在您已经创建了您的.p12证书,它将需要上传到Zendesk管理中心的管理员在您的Zendesk帐户。亚博如果您不是管理员,请联系您帐户上的管理员,以协助您执行此步骤。

如果你已经启用了iOS消息

  1. 在Zendes亚博k管理中心,单击Channels图标,然后单击消息传递
  2. 点击iOS,然后单击通知选项卡。
  3. 拖放您的。p12证书或单击链接找到并上传您的证书。

如果你没有启用iOS消息

  1. 在Zendes亚博k管理中心,单击Channels图标,然后单击消息设置
  2. 在“设置消息传递”页上,选择复选框到为您的帐户启用消息传递
  3. 点击管理渠道
  4. 点击添加通道,然后点击iOS
  5. 按照提示配置通道,然后单击完成
  6. 如果iOS通道尚未打开,请单击通知选项卡。
  7. 拖放您的。p12证书或单击链接找到并上传您的证书。

步骤3 -在项目中添加推送通知功能

  1. 选择您的项目目标。

  2. 转到签名和功能选项卡。

  3. 添加推送通知能力与+能力按钮。

步骤4—设置APS环境权限

属性时自动添加推送通知能力。检查应用程序的.entitlements文件,以确保一个APS的环境键存在并且正在使用生产

步骤5 -请求用户授权推送通知

使用注册推送通知UNUserNotificationCenter在你的AppDelegate应用程序(didFinishLaunchingWithOptions)

斯威夫特

             
进口UserNotifications函数application(_ application: UIApplication)didFinishLaunchingWithOptions: [UIApplication.]LaunchOptionsKey: Any]) -> Bool {registerForPushNotifications ()还真}私有函数registerForPushNotifications() {let notificationCenter = UNUserNotificationCenter.current()notificationCenter.delegate = selfnotificationCenter。请求Authorization(options: [.alert, .sound, .badge]) { allowed, _ in允许守卫,否则{返回}DispatchQueue.main.async {UIApplication.shared.registerForRemoteNotifications ()}}}

objective - c

             
进口<UserNotifications/UserNotificationsh>-保龄球应用程序UIApplication*应用didFinishLaunchingWithOptionsNSDictionary*launchOptions自我registerForPushNotifications]返回是的}-无效registerForPushNotificationsUNUserNotificationCenter*中心=UNUserNotificationCenter currentNotificationCenter]中心委托=自我中心requestAuthorizationWithOptionsUNAuthorizationOptionSound|UNAuthorizationOptionAlert|UNAuthorizationOptionBadgecompletionHandler^BOOL允许NSError*_Nullable错误如果允许设置dispatch_get_main_queue^UIApplication sharedApplication]registerForRemoteNotifications]}}}]}

步骤6 -添加Zendesk SD亚博K到您的应用程序

添加Zendes亚博k SDK并更新PushNotifications使用接收到的设备令牌初始化。

覆盖应用程序(didRegisterForRemoteNotificationsWithDeviceToken)在你的AppDelegate

斯威夫特

             
进口Zende亚博skSDKMessaging函数application(_ application: UIApplication, didreregisterforremotenotifationswithdevicetoken deviceToken: Data) {PushNotifications.updatePushNotificationToken (deviceToken)}

objective - c

             
进口<亚博ZendeskSDKMessaging/亚博ZendeskSDKMessagingh>-无效应用程序UIApplication*应用didRegisterForRemoteNotificationsWithDeviceTokenNSData*deviceTokenZDKPushNotifications updatePushNotificationTokendeviceToken]}

步骤7 -在应用程序中显示推送通知

符合UNUserNotificationCenterDelegate

斯威夫特

             
类AppDelegate: UIResponder UIApplicationDelegate UNUserNotificationCenterDelegate

objective - c

             
@ interfaceAppDelegateUIResponder<UIApplicationDelegateUNUserNotificationCenterDelegate>

实现userNotificationCenter (willPresent)在应用程序处于前台时显示通知。

斯威夫特

             
UNUserNotificationCenter: UNUserNotificationCenterwillPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {let userInfo = notification.request.content.userInfo//检查收到的推送通知是否应该由Messaging显示let shouldbedisplay = pushnotification . shouldbedisplay (userInfo)switch shouldbedisplay {案例.messagingShouldDisplay://此推送属于消息传递,SDK能够将其显示给最终用户if #available(iOS 14.0, *) {completionHandler([。横幅,声音,徽章])} else {completionHandler([。Alert, .sound, .badge])}案例.messagingShouldNotDisplay://此推送属于消息传递,但不应该显示给最终用户completionHandler ([])案例.notFromMessaging://此推送不属于消息传递//如果你的应用中有推送通知,把你的代码放在这里//如果没有,就调用completionHandlercompletionHandler ([])@unknown default:中断}}

objective - c

             
-无效userNotificationCenterUNUserNotificationCenter*中心willPresentNotificationUNNotification*通知withCompletionHandler无效^UNNotificationPresentationOptionscompletionHandlerid用户信息=通知请求内容用户信息//检查收到的推送通知是否应该由Messaging显示ZDKPushResponsibility shouldBeDisplayed=ZDKPushNotifications shouldBeDisplayed用户信息]开关shouldBeDisplayed情况下ZDKPushResponsibilityMessagingShouldDisplay//此推送属于消息传递,SDK能够将其显示给最终用户如果@可用iOS14.0*completionHandlerUNNotificationPresentationOptionBanner|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge}其他的completionHandlerUNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge}打破情况下ZDKPushResponsibilityMessagingShouldNotDisplay//此推送属于消息传递,但不应该显示给最终用户completionHandlerUNNotificationPresentationOptionNone打破情况下ZDKPushResponsibilityNotFromMessaging//此推送不属于消息传递//如果你的应用中有推送通知,把你的代码放在这里//如果没有,调用completionHandler和breakcompletionHandlerUNNotificationPresentationOptionNone打破}}

步骤8 -处理应用中的推送通知

实现userNotificationCenter (didReceive)当通知被点击时处理。

斯威夫特

             
UNUserNotificationCenter: UNUserNotificationCenterdidReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {let userInfo = response.notification.request.content.userInfo//检查收到的推送通知是否应该由Messaging处理let shouldbedisplay = pushnotification . shouldbedisplay (userInfo)switch shouldbedisplay {案例.messagingShouldDisplay://这个推送属于消息传递,当最终用户与它交互时,SDK能够处理PushNotifications.handleTap(userInfo) {viewController in//处理在这里显示返回的viewController}案例.messagingShouldNotDisplay://这个推送属于消息传递,但是交互不应该由SDK处理打破案例.notFromMessaging://此推送不属于消息传递//如果你的应用中有推送通知,把你的代码放在这里//如果没有,就调用' break '打破@unknown default:中断}completionHandler ()}

objective - c

             
-无效userNotificationCenterUNUserNotificationCenter*中心didReceiveNotificationResponseUNNotificationResponse*响应withCompletionHandler无效^无效completionHandlerid用户信息=响应通知请求内容用户信息//检查收到的推送通知是否应该由Messaging处理ZDKPushResponsibility shouldBeDisplayed=ZDKPushNotifications shouldBeDisplayed用户信息]开关shouldBeDisplayed情况下ZDKPushResponsibilityMessagingShouldDisplay//这个推送属于消息传递,当最终用户与它交互时,SDK能够处理ZDKPushNotifications handleTap完成用户信息^ui*_Nullable viewController//处理在这里显示返回的viewController}]打破情况下ZDKPushResponsibilityMessagingShouldNotDisplay//这个推送属于消息传递,但是交互不应该由SDK处理打破情况下ZDKPushResponsibilityNotFromMessaging//此推送不属于消息传递//如果你的应用中有推送通知,把你的代码放在这里//如果不是,就调用break打破}completionHandler}

请注意当应用程序处于后台状态时,返回的viewController将允许你显示对话。当应用处于kill状态时,它会返回nil,因为SDK还没有初始化。

如果你想改变那个行为,你将不得不实现你自己对推送显示的处理,以及处理SDK的初始化和messagingViewController