使用交互式推送通知调用 Web 服务 iOS 8

Call web service with interactive push notification iOS 8

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

收到通知后,我在锁上有两个按钮screen.Both,它们应该启动两个 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()

用于 Web 服务调用。

但是它 returns 连接错误。

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

编辑:

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

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

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

如果您打开后台模式,它应该可以工作,您可以在功能和 select 远程通知中执行此操作。

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

Note: When your app resumes execution the actual error returned by a socket's whose resources have been reclaimed is purposely not specified here to allow for future refinements. However, in many cases the error will be EBADF, which is probably not what you were expecting! Under normal circumstances EBADF means that the app has passed an invalid file descriptor to a system call. However, in the case of a socket whose resources have been reclaimed, it does not mean that the file descriptor was invalid, just that the socket is no longer usable.

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

的实现

这对我有用。

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