1

我是 xcode 和 ios 开发的新手。我使用 swift 编写新项目。

我想添加扫描信标并获取最近信标的消息\附件的代码。我希望该应用程序还可以告诉该信标何时不再在范围内。

1) 我看到 iBeacons 无法获取信标的消息\附件?

2)我看到了谷歌示例代码。我只需要没有ui的代码逻辑。所以我想我会努力将 UI 从逻辑中分离出来。我只想确定:

我只能留下这个代码吗?(删除let pubMessage: GNSMessage = GNSMessage

/// Starts publishing the specified name and scanning for nearby devices that are publishing
        /// their names.
        func startSharingWithName(name: String) {
            if let messageMgr = self.messageMgr {
                // Show the name in the message view title and set up the Stop button.
                messageViewController.title = name

                // Publish the name to nearby devices.
                let pubMessage: GNSMessage = GNSMessage(content: name.dataUsingEncoding(NSUTF8StringEncoding,
                    allowLossyConversion: true))
                publication = messageMgr.publicationWithMessage(pubMessage)

                // Subscribe to messages from nearby devices and display them in the message view.
                subscription = messageMgr.subscriptionWithMessageFoundHandler({[unowned self] (message: GNSMessage!) -> Void in
                    self.messageViewController.addMessage(String(data: message.content, encoding:NSUTF8StringEncoding))
                    }, messageLostHandler: {[unowned self](message: GNSMessage!) -> Void in
                        self.messageViewController.removeMessage(String(data: message.content, encoding: NSUTF8StringEncoding))
                    })
            }
        }

因为我不需要发布-订阅模型,只需扫描信标

为什么我添加了 viewController 代码并且我看到了一个新的 UI?

故事板只是 viewController 的 ui 编辑器?

我已经阅读了 Google doc和他们的github以及本教程

但无法让它在我的项目中工作。

4

0 回答 0