LoginSignup
4
3

More than 5 years have passed since last update.

MAMORIO SDK (iOS版) 最初の一歩

Posted at

背景

Android版のMAMORIO SDKを使って、マラソンアプリを作成して、すれ違いを検出することに成功したので、次回のマラソンでは、iOS版のアプリを作ってやってみようと思い、iOS版のSDKを使ってみた。
READMEには記述されていない部分を対処しないとつまずくと思われるので、はじめの一歩をここに記す。

動作環境(2017/11/9現在)

XCode Version 9.1
MAMORIO SDK release branch (v20171108213815) (https://github.com/otoshimono/mamorio-sdk-ios-bin)
Apple iPhone X(iOS 11.1)

XCodeで新規プロジェクトを作成する

Single View Application選択
LanguageはSwift
DeviceはUniversal
Use Core Data、Include Unit test、Include UI Testのチェックを外す
でプロジェクトを作成した。

CocoaPod経由でSDKを導入する

・XCodeを閉じる
・コンソールで、プロジェクトのフォルダに入って
pod init
で、PodFileを作成する。
・PodFileを下記のように編集する

PodFile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '9.0'

target 'Test Mamorio' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Test Mamorio
  pod 'MamorioSDK', :git => 'https://github.com/otoshimono/mamorio-sdk-ios-bin.git'
end

・SDKのインストール
pod install
でプロジェクトにSDKがインストールされる
・再度、XCodeで開く

Info.plistに追記

MAMORIO SDKは、位置情報とアクティビティのAPIを内部で呼び出すので、Info.plistに追記します。

NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
NSMotionUsageDescription

プロバティで表示した場合

171109-0003.png

XMLで表現した場合

171109-0004.png

検証コード

ViewController.swift
//
//  ViewController.swift
//  Test Mamorio
//
//  Created by Kazuyuki Eguchi on 2017/11/09.
//  Copyright © 2017年 Kazuyuki Eguchi. All rights reserved.
//

import UIKit
import MamorioSDK

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        // MAMORIO SDKを初期化
        MamorioSDK.setUp("YOUR_APP_TOKEN")

        // temp user
        User.signUpAsTemporalUser() { [weak self] (user, error) -> Void in
            if let error = error {
                print("捜索専用ユーザーの登録に失敗しました。エラーメッセージ:\(error.description)")
            } else {
                print("捜索専用ユーザーの登録に成功しました。")
                // メインスレッドでコールされるようにする
                DispatchQueue.main.async {
                    self?.step2()
                }
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func step2()
    {
        // MAMORIOを探す
        MamorioSDK.rangingStart({() -> Void in
            print("レンジングの開始に成功しました。")
        }, onError: {(error) -> Void in
            print("レンジングの開始に失敗しました。エラーメッセージ:\(error.description)")
        }, onMamoriosEnter: {(mamorios : Array<Mamorio> , othersMamorios: Array<Mamorio>) in
            print("MAMORIO発見 自分のMAMORIO=\(mamorios.count) , 他人のMAMORIO=\(othersMamorios.count)")
        }, onMamorioExit: {(mamorio : Mamorio) in
            print("自分のMAMORIOを見失いました。紛失を伝えましょう。")
        })
    }
}

所感

Android版と比較して、ちょっと動作が異なる部分(バグ!?)とAPIも少なくなっている部分があるので、差分が無くなるのと修正されることに期待したいと思います。(バグレポートはしているのですが、それを仕様とするか?はわかりません)

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3