【问题标题】:Swift2 how to disable remote notification GCMSwift2如何禁用远程通知GCM
【发布时间】:2015-11-28 19:08:53
【问题描述】:

我正在使用 GCM 和来自服务器的远程通知开发应用程序。我想让 UISwitch 禁用和启用该操作。 我尝试了类似的方法,但不知道下一步。

let notificationType = UIApplication.sharedApplication().currentUserNotificationSettings()!.types
if notificationType != UIUserNotificationType.None {
   print("disabled")
   //what to do here?
} else {
   print("enabled")
   //what to do here?
}

【问题讨论】:

    标签: notifications google-cloud-messaging apple-push-notifications swift2 ios9


    【解决方案1】:

    您应该调用deleteToken()deleteID() 方法从GCM 取消注册或取消订阅您的设备,您可以阅读this documentation 了解更多详情。

    InstanceID deleteToken(),受众设置为应用服务器的发件人 ID,范围设置为 GCM。这会阻止来自特定应用服务器的消息(包括主题消息)

    InstanceID deleteID()。这会停止来自所有应用服务器的所有先前注册和主题订阅的消息

    示例代码:

    删除ID:

       GGLInstanceID.sharedInstance().deleteIDWithHandler { 
           (error: NSError) -> Void in
    
       }
    

    删除令牌:

        GGLInstanceID.sharedInstance().deleteTokenWithAuthorizedEntity(gcmSenderID, scope: kGGLInstanceIDScopeGCM) { 
          (error: NSError) -> Void in
    
        }
    

    【讨论】:

      猜你喜欢
      • 2013-02-02
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多