1

Swift を使用して Microsoft Band SDK を実装しようとしています。コードをセットアップしようとすると、このエラーが発生し続けます。

class ViewController: UIViewController, UITableViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MSBClientManagerDelegate, UIScrollViewDelegate {

これまでに見たことはありませんが、Objective C のサンプルを Swift に変換しようとしたこともありません。

どんな助けでも大歓迎です!

編集:これはObjective Cのプロトコルです

@protocol MSBClientManagerDelegate<NSObject>

- (void)clientManager:(MSBClientManager *)clientManager clientDidConnect:(MSBClient *)client;
- (void)clientManager:(MSBClientManager *)clientManager clientDidDisconnect:(MSBClient *)client;
- (void)clientManager:(MSBClientManager *)clientManager client:(MSBClient *)client didFailToConnectWithError:(NSError *)error;

@end

EDIT 2: 推奨される Swift Helper クラスを使用した後

これは、接続を設定しようとしている方法です。

 var clients:NSArray = bandHelper.attachedClients()!
    var firstClient: MSBClient = clients[0] as MSBClient

if (clients.count == 0){
    println("The band is not detected")
    return
}

これをどのように設定すればよいかわかりません

bandHelper.connectClient(firstClient, {completion: (connected:true -> void in)})
println("Please wait...connecting to band")

次に、写真をバンドに送信しようとすると、この機能が動作しません

bandHelper.client?.personalizationManager.updateMeTileImage(bandScaledImage, { (completionHandler: NSError!) -> Void in
           NSLog("%@", NSError())})

ヘルパー クラスを使用することで、私はうんざりしています。どんな助けでも大歓迎です!

4

1 に答える 1

2

サンプルプロジェクト

ハプティクスをバンドに送信できる Microsoft Band Kit iOS 用のサンプル Swift プロジェクトをリンクしました。ここのリンクを見つけてください: http://droolfactory.blogspot.com/2015/03/ios-swift-example-of-connecting-with.html


Microsoft バンド ブリッジング ヘッダー

まず、Objective-C クラスを Swift で使用できるように変換するには、ブリッジング ヘッダーを作成します。MicrosoftBandKit-iOS フレームワークだけの場合、私のものは次のようになります。

#ifndef ModuleName_Bridging_Header_h
#define ModuleName_Bridging_Header_h

#import <MicrosoftBandKit_iOS/MicrosoftBandKit_iOS.h>

#endif

ModuleName をアプリ モジュールの名前に置き換えてください。ブリッジ ヘッダー ファイルの詳細については、https ://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html を参照してください。


バンド ヘルパー クラス

次に、シングルトンを使用して Band を管理するヘルパー クラス (BandManager) で MSBClientManagerDelegate をラップしました。ここに要点があります(https://gist.github.com/mthistle/8f6eb30c68a918fc6240

この要旨のコードは次のとおりです。

import Foundation

let kConnectionChangedNotification = "kConnectionChangedNotification"
let kConnectionFailedNotification  = "kConnectionFailedNotification"

private let _SharedBandManagerInstance = BandManager()

class BandManager : NSObject, MSBClientManagerDelegate {

    private(set) var client: MSBClient?
    private var connectionBlock: ((Bool) -> ())?
    private var discoveredClients = [MSBClient]()

    private var clientManager = MSBClientManager.sharedManager()

    class var sharedInstance: BandManager {
        return _SharedBandManagerInstance
    }

    override init() {
        super.init()
        self.clientManager.delegate = self
    }

    func attachedClients() -> [MSBClient]? {
        if let manager = self.clientManager {
            self.discoveredClients = [MSBClient]()
            for client in manager.attachedClients() {
                self.discoveredClients.append(client as! MSBClient)
            }
        }
        return self.discoveredClients
    }

    func disconnectClient(client: MSBClient) {
        if (!client.isDeviceConnected) {
            return;
        }
        if let manager = self.clientManager {
            manager.cancelClientConnection(client)
            self.client = nil
        }
    }

    func connectClient(client: MSBClient, completion: (connected: Bool) -> Void) {
        if (client.isDeviceConnected && self.client == client) {
            if (self.connectionBlock != nil)
            {
                self.connectionBlock!(true)
            }
            return;
        }

        if let connectedClient = self.client {
            self.disconnectClient(client)
        }

        self.connectionBlock = completion;
        self.clientManager.connectClient(client)
    }

    func clientManager(clientManager: MSBClientManager!, clientDidConnect client: MSBClient!) {
        if (self.connectionBlock != nil) {
            self.client = client
            self.connectionBlock!(true)
            self.connectionBlock = nil
        }

        self.fireClientChangeNotification(client)
    }

    func clientManager(clientManager: MSBClientManager!, clientDidDisconnect client: MSBClient!) {
        self.fireClientChangeNotification(client)
    }

    func clientManager(clientManager: MSBClientManager!, client: MSBClient!, didFailToConnectWithError error: NSError!) {
        if error != nil {
            println(error)
        }
        NSNotificationCenter.defaultCenter().postNotificationName(kConnectionFailedNotification, object: self, userInfo: ["client": client])
    }

    func fireClientChangeNotification(client: MSBClient) {
        NSNotificationCenter.defaultCenter().postNotificationName(kConnectionChangedNotification, object: self, userInfo: ["client": client])
    }

}
于 2015-03-30T06:03:04.780 に答える