【问题标题】:Twilio - Inviting Users on a private channel by sending them remote notificationsTwilio - 通过发送远程通知在私人频道上邀请用户
【发布时间】:2016-09-07 05:31:49
【问题描述】:

我正在尝试为 IP 消息传递、视频对话、呼叫和 SMS 实施 Twilio SDK。就要求而言,Twilio 完全符合所有要求。但是,我们在通过向用户发送远程通知来邀请他们加入私人频道方面面临一些挑战。然而,我们搜索了文档,但似乎没有找到可以为我们的问题陈述指明解决方案的文档句柄。

步骤-

  • 使用设备 UUID 请求令牌

  • 使用新生成的令牌创建 IPMessagingClient 实例

    let accessManager= TwilioAccessManager.init(token: token, delegate: self)  
    let client = TwilioIPMessagingClient.ipMessagingClientWithAccessManager(accessManager, properties: nil, delegate: self)
    
  • 在 IPMessagingClient 实例上调用 registerWithToken

    ipMessagingClient.registerWithToken(deviceToken)
    
  • 如果用户想与其他用户聊天

    • 我们检查私人频道是否存在

      let availableChannel = channels?.channelWithUniqueName(defaultChannel)
      
    • 如果频道存在,我们让登录用户加入频道

      availableChannel.joinWithCompletion({ (result) in
                      if result.isSuccessful(){ ... }})
      
    • 如果频道不存在,则我们创建新的私人频道

      let options: [NSObject:AnyObject] = [
          TWMChannelOptionFriendlyName: defaultChannel,
          TWMChannelOptionUniqueName: defaultChannel,
          TWMChannelOptionType: TWMChannelType.Private.rawValue
      ]  
      
      channels?.createChannelWithOptions(options, completion: { (result, channel) in
              if result.isSuccessful(){
                  channel.joinWithCompletion({ (result) in
                      if result.isSuccessful(){ ... }})
      
    • 一旦用户成功加入频道,我们会向其他用户发送加入同一频道的邀请。

      availableChannel.members.inviteByIdentity(other_user_name, completion: { 
          (result) in
              if result.isSuccessful(){ ... })
      
    • 然后我们等待在 AppDelegate 中可用的 didReceiveRemoteNotification 触发。在其中我们有一段代码通过徽章或消息或声音显示通知。 <- problem Statement

这就是问题出现的地方,didReceiveRemoteNotification 根本没有触发。

【问题讨论】:

  • 您是否按照所有步骤设置为receive push notifications from IP Messaging?您是否能够接收其他事件的推送通知,例如用户收到新消息?
  • 嘿 Philnash,是的,我按照相同的文档编写推送通知。另外,我首先为生产创建了苹果推送证书,但是,后来我为开发添加了另一个,但是它没有用。另外,我尝试向用户发送一条消息,但是,它也不会触发 didReceiveRemoteNotification 委托。

标签: ios twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

你需要make sure you have notifications enabled for the IP Messaging service你正在使用。

目前您需要使用 REST API 来执行此操作,不过很快Twilio console 将对此提供支持。

同时,下面是一个示例,说明如何为频道邀请和新消息启用推送通知:

curl -X POST https://ip-messaging.twilio.com/v1/Services/{service sid} \
 -d 'Notifications.NewMessage.Enabled=true' \
 -d 'Notifications.NewMessage.Template=A New message in ${CHANNEL} from ${USER}: ${MESSAGE}' \
 -d 'Notifications.InvitedToChannel.Enabled=true' \
 -d 'Notifications.InvitedToChannel.Template=${USER} has invited you to join the channel ${CHANNEL}' \
 -u '{twilio account sid}:{twilio auth token}'

只需在上面替换您的 Account SID、Auth Token 和 Messaging Service SID。查看types of notification you can enable and notification templates in the documentation上的所有详细信息。

【讨论】:

  • 你成就了我的一天!!万分感谢。它就像一个魅力。
猜你喜欢
  • 1970-01-01
  • 2017-12-31
  • 1970-01-01
  • 2021-07-15
  • 2019-09-09
  • 2023-01-05
  • 2018-11-23
  • 2018-06-11
  • 1970-01-01
相关资源
最近更新 更多