1

私は推定ビーコンに取り組んでいます。

スイッチケース「即時」にあるときにViewControllerを提示しようとします。しかし、ビューが読み込まれると、警告が表示されます:

2014-03-13 02:44:26.017 ProximityDemo[856:60b] 警告: ウィンドウ階層にないビューで表示しようとしています!

なんで ?新しいビューを使用している間、presentView メソッドはまだ機能していると思います。

また、新しいビューにいるときは、「近く」のケースにいるときに古いビューにポップしたいと思います

新しい ViewController にすべてのコードを実装する必要があると思いますか? (presentProductViewController) すべての近接/距離制御を 1 つのコントローラーだけで行う方法はありますか?

これが私のコードです:

ESTViewController :

#import "ESTViewController.h"
#import <ESTBeaconManager.h>
#import "PresentProductViewController.h"

@interface ESTViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation ESTViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];



}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    NSString* labelText = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            labelText = [labelText stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            labelText = [labelText stringByAppendingString: @"Immediate"];

            PresentProductViewController *showViewController = [[PresentProductViewController alloc] initWithNibName:@"PresentProductViewController" bundle:nil];

            [self presentViewController:showViewController animated:YES completion:nil];

            break;
        }
        case CLProximityNear:
        {
            labelText = [labelText stringByAppendingString: @"Near"];
            break;

            //[self.navigationController popToRootViewControllerAnimated:YES];
            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];
        }
        case CLProximityFar:
        {
            labelText = [labelText stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

    self.distanceLabel.text = labelText;
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

PresentProductViewController :

#import "PresentProductViewController.h"
#import <ESTBeaconManager.h>
#import "ESTViewController.h"

@interface PresentProductViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) ESTBeacon* selectedBeacon;

@end

@implementation PresentProductViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.activityIndicator startAnimating];

/////////////////////////////////////////////////////////////
// setup Estimote beacon manager

// craete manager instance
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;

// create sample region object (you can additionaly pass major / minor values)
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID
                                                              identifier:@"EstimoteSampleRegion"];

// start looking for estimote beacons in region
// when beacon ranged beaconManager:didRangeBeacons:inRegion: invoked
[self.beaconManager startRangingBeaconsInRegion:region];


}

-(void)beaconManager:(ESTBeaconManager *)manager
 didRangeBeacons:(NSArray *)beacons
        inRegion:(ESTBeaconRegion *)region
{
if([beacons count] > 0)
{

    if(!self.selectedBeacon)
    {
        // initialy pick closest beacon
        self.selectedBeacon = [beacons objectAtIndex:0];
    }
    else
    {
        for (ESTBeacon* cBeacon in beacons)
        {
            // update beacon it same as selected initially
            if([self.selectedBeacon.major unsignedShortValue] == [cBeacon.major unsignedShortValue] &&
               [self.selectedBeacon.minor unsignedShortValue] == [cBeacon.minor unsignedShortValue])
            {
                self.selectedBeacon = cBeacon;
            }
        }
    }



    // beacon array is sorted based on distance
    // closest beacon is the first one

    self.labelText.text = [NSString stringWithFormat:
                           @"Major: %i, Minor: %i\nRegion: ",
                           [self.selectedBeacon.major unsignedShortValue],
                           [self.selectedBeacon.minor unsignedShortValue]];

    // calculate and set new y position
    switch (self.selectedBeacon.proximity)
    {
        case CLProximityUnknown:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Unknown"];
            break;
        }
        case CLProximityImmediate:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Immediate"];
            break;
        }
        case CLProximityNear:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Near"];
            break;

            //UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
            //UIViewController *initViewController = [storyBoard instantiateInitialViewController];

            //[self.navigationController pushViewController:initViewController animated:YES];

            //ESTViewController *initViewController = [[ESTViewController alloc]init];
            //[self presentViewController:initViewController animated:YES completion:nil];

            //[self.navigationController popToRootViewControllerAnimated:YES];

        }
        case CLProximityFar:
        {
            self.labelText.text = [self.labelText.text stringByAppendingString: @"Far"];
            break;
        }

        default:
            break;
    }

}
}

-(void)viewDidDisappear:(BOOL)animated
{
[self.activityIndicator stopAnimating];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

私は間違っていると確信しています。ご協力いただきありがとうございます。

4

1 に答える 1

1

は、 を提示した場合でも、 をESTBeaconManager介して最新の変更を継続的に配信している可能性があります。私は次のことが起こると思います:didRangeBeacons:inRegionPresentProductViewController

  1. ESTViewControllerは、ビーコンのdidRangeBeacons:inRegion空でない配列で呼び出されます。
  2. proximity選択したビーコンのプロパティは でCLProximityImmediatePresentProductViewControllerモーダルに表示されます。
  3. 提示中(提示されていない)、viewcontrollerESTViewControllerdidRangeBeacons:inRegion新しい変更で呼び出されます。繰り返しになりますが、ビーコンはすぐに近接し、の新しいインスタンスがPresentProductViewControllerモーダルに提示されます。

ViewControllerプログラミングガイドより

ビュー コントローラ オブジェクトは、一度に 1 つのビュー コントローラを提示できます。

上記の前提が正しい場合、複数のビューコントローラーを同時にモーダルに表示しようとしていますが、これは有効なアクションではありません。ビューが消えたらビーコンの測距を停止し、表示されたら再び測距を開始することができます。これにより、ビーコン マネージャーがESTViewControllerビュー コントローラーを提示する立場にない間、変更を通知できなくなります。これを達成するためのオーバーライドviewWillDisappearviewWillAppearメソッド:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.beaconManager stopRangingBeaconsInRegion:region];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.beaconManager startRangingBeaconsInRegion:region];
}
于 2014-03-13T21:15:03.490 に答える