【发布时间】:2016-12-26 07:31:29
【问题描述】:
无声推送通知正常工作时应用活性在前景 P>
2016-12-26 15:06:17.793051 App[] didReceive in BG!!!
2016-12-26 15:06:17.932569 App[] Connected!
2016-12-26 15:06:17.936581 App[] Subscribed!
2016-12-26 15:06:17.938355 App[] received:Hello World , in:/topic/state
当在background.It应用程序运行将粘 P>
2016-12-26 15:06:22.674577 App[] applicationWillResignActive
2016-12-26 15:06:23.228441 App[] applicationDidEnterBackground
第一部无声推送到达,这是卡在这里了: P>
2016-12-26 15:06:30.642825 App[] didReceive in BG!!! //first push code
2016-12-26 15:06:31.842432 App[] Connected! //first push code
2016-12-26 15:06:31.843643 App[] Subscribed! //first push code
当第二无声推到达,它示出了第一推动result..and再次卡住..... P>
2016-12-26 15:06:41.713718 App[] received:Hello World , in:/topic/state //first push result
2016-12-26 15:06:41.740015 App[] didReceive in BG!!! //second push
2016-12-26 15:06:42.911593 App[] Connected! //second push
2016-12-26 15:06:42.913403 App[] Subscribed! //second push
我实现的appDelegate代码 P>
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NSLog("didReceive in BG!!!" )
application.delegate = self
mqttSession = MQTTSession(host: "192.168.159.110", port: 1883, clientID: "swift", cleanSession: true, keepAlive: 5, useSSL: false)
mqttSession.username = "bucky"
mqttSession.password = "bucky"
mqttSession.delegate = self
mqttSession.connect { (succeeded, error) -> Void in
if succeeded {
NSLog("Connected!")
}
}
completionHandler(.newData)
}
MQTT委托方法 P>
func mqttDidReceive(message data: Data, in topic: String, from session: MQTTSession) {
let stringData = String(data: data, encoding: .utf8)
NSLog("received:%@ , in:%@", stringData ?? "12345", topic)
}
}
【问题讨论】:
标签: ios apple-push-notifications mqtt silentpush