1

我在使用 libmosquitto 开发 iOS 应用程序时遇到了一些问题

在我的代码 AppDelegate.swift

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MosquittoClientDelegate{

    var window: UIWindow?
    var client: MosquittoClient?

    func didPublish(messageId: UInt) {
        println( "didPublish \(messageId)" )
    }
    func didReceiveMessage(mosq_msg: MosquittoMessage!) {
        println( "didReceiveMessage [ \(mosq_msg.mid)-\(mosq_msg.topic) ] \(mosq_msg.payload)" )
    }
    func didDisconnect() {
        println( "didDisconnect" )
    }
    func didConnect(code: UInt) {
        println( "didConnect \(code)" )
        if code == UInt(MOSQ_ERR_SUCCESS.value){
            client?.subscribe("sample", withQos: 1)
        }
    }
    func didSubscribe(messageId: UInt, grantedQos qos: [AnyObject]!) {
        println( "didSubscribe" )
    }
    func didUnsubscribe(messageId: UInt) {
        println( "didUnsubscribe \(messageId)" )
    }

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        
        client = MosquittoClient(clientId: "qq")
        client?.host = "stick.coffee"
        client?.port = 1883
        client?.delegate = self
        client?.connect()
        return true
    }
}

除了退出应用程序外,这可以正常工作。

即使退出应用程序,我也想要接收消息。

我发现有一些背景模式。

  • 音频和 AirPlay
  • 位置更新
  • IP语音
  • 报亭下载
  • 外部附件通讯
  • 使用蓝牙 LE 配件
  • 充当蓝牙 LE 配件
  • 后台获取
  • 远程通知

什么是最适合我的模式?或者这个存根有一些例子吗?

4

1 回答 1

0

是的,我发现没有后台运行的方法。

但是如果不需要上传 AppleStore,voip 可以在后台运行。

所以我用voip实现。

于 2015-03-02T02:17:47.363 回答