【问题标题】:Call web service with interactive push notification iOS 8使用交互式推送通知 iOS 8 调用 Web 服务
【发布时间】:2015-08-13 09:35:01
【问题描述】:

我正在尝试在我的应用中实现交互式推送通知。应用成功收到通知。

收到通知后,我在锁定屏幕上有两个按钮。它们都应该启动两个 Web 服务

这是我在application handleActionWithIdentifier中的代码

    func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {


    let aps = userInfo["aps"] as NSDictionary
    let id = aps["id"] as Int
    let notification = Notifications()
    notification.notificationId = NSNumber(integer: id)

    if identifier == "APPROVE"{
        APIManager.sharedInstance.approveApprovalRequest(notification)
    }
    else if identifier == "DELETE"{
        APIManager.sharedInstance.dismissBulletin(notification)
    }
    completionHandler()
}

我用过

 NSURLSession.sharedSession().dataTaskWithRequest(request, 
    completionHandler: { (data, response, error) -> Void in}).resume()

用于网络服务调用。

但它返回连接错误。

我该如何解决这个问题。任何帮助表示赞赏。

编辑:

这是我在日志中收到的错误

Error Domain=NSPOSIXErrorDomain Code=9 "The operation couldn’t be completed.Bad file descriptor"

UserInfo=0x1552ca00 {_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=9}

【问题讨论】:

    标签: ios swift push-notification


    【解决方案1】:

    这对我有用。

    let data = NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error: error)
    

    【讨论】:

      【解决方案2】:

      如果您打开了后台模式,它应该可以工作,您可以在 Capabilities 中执行此操作并选择 Remote Notifications。

      更新 在多任务和网络中,如果应用程序被挂起并且套接字被回收,您可能会收到 EBADF 错误阅读更多关于此here

      注意:当您的应用恢复执行时,此处特意未指定资源已被回收的套接字返回的实际错误,以便将来进行改进。但是,在许多情况下,错误将是 EBADF,这可能不是您所期望的!在正常情况下,EBADF 意味着应用程序已将无效的文件描述符传递给系统调用。但是,对于资源被回收的socket,并不代表文件描述符无效,只是socket不再可用。

      提示:检查APIManager.sharedInstance.approveApprovalRequest(notification)的实现

      【讨论】:

      • 我已打开后台模式并选择了远程通知和后台获取。但没有帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多