工厂模式:iBeacon代理没有被执行文件调用 [英] Factory pattern : iBeacon Delegates are not called from implemention file

查看:177
本文介绍了工厂模式:iBeacon代理没有被执行文件调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在信标扫描模块中引入了工厂模式。我提到了 http://crosbymichael.com/objective-c-design-patterns-factory .html

I introduced "Factory Pattern" in my beacon scanning module. I referred http://crosbymichael.com/objective-c-design-patterns-factory.html

在我的工厂类中,两种模式的信标在接口类 PCGoogleBeacon.h PCAppleBeacon.h

In my Factory class, 2 modes of beacons are switched between Interface classes "PCGoogleBeacon.h" and "PCAppleBeacon.h".

//工厂

typedef enum beaconMode {
    iBeacon,
    Eddystone
} BeaconMode;

@interface PCBeaconFinder : NSObject

+(id) searchForBeaconMode:(BeaconMode) beaconMode;

@end

//实施工厂

+(id) searchForBeaconMode:(BeaconMode) beaconMode
{

    switch (beaconMode ) {

        case iBeacon:

            return   [PCAppleBeacon new];

            break;

        case Eddystone:

            return   [PCGoogleBeacon new];

            break;

        default: NSLog(@"UNKOWN BEACON MODE");


    }

}

在我的接口类的实现文件中。

In my Implementation file for interface classes.

//Header file

@protocol PCGetBeacon <NSObject>

-(void) scanBeaconsWithUUID:(NSString *) beaconId;

@end

//在实现文件中。 - 执行模式1

//In the implementation file. — Implementation of Mode 1

#import "PCAppleBeacon.h"

@implementation PCAppleBeacon

-(void) scanBeaconsWithUUID:(NSString *) beaconId {


    self.proximityContentManager = [[ProximityContentManager alloc]
                                    initWithBeaconIDs:@[

                                                        [[BeaconID alloc] initWithUUIDString:beaconId major:0 minor:0]
                                                        ]
                                    beaconContentFactory:[EstimoteCloudBeaconDetailsFactory new]];

    self.proximityContentManager.delegate = self;

    [self.proximityContentManager startContentUpdates];


    NSLog(@"----------- > iBeacon  Implementation Called ");


}

//iBeacon Delegates goes here …


@end

//同样的上述文件 - 模式2的实现

// In the same above file— Implementation of Mode 2

#import "PCGoogleBeacon.h"

@implementation PCGoogleBeacon

-(void) scanBeaconsWithUUID:(NSString *) beaconId {

    _scanner.delegate = self;

    [_scanner startScanning];

    NSLog(@"----------- > EDDYSTONE  Implementation Called ");

}

//EDDYSTONE Delegates goes here …

@end

一切都很好。可以从MainController切换,

Everything is fine. Able to switch as from MainController,

 id beaconFinderObject =   [PCBeaconFinder searchForBeaconMode:iBeacon];  //or ‘Eddystone’ for Google beacon interface.

 [beaconFinderObject scanBeaconsWithUUID:@"B0702880-A295-A8AB-F734-031A98A512DE"];

但是为什么不调用相应类的代理。 ?

注意:信标位于范围内。

推荐答案

类别解决了我的问题。

说明
以上类的代理方法不被调用,因为2次实例化。第一次在实施工厂类中实例化,并设置它的代表。第二次从主视图控制器,其协议没有实现,因此接收器失败。

Explanation : Delegate methods of above classes are not called because 2 times those instantiated. First time instantiated in 'Implementation of Factory Class' along with setting it's delegates. Second time from the class Main view controller, where it's protocols are not implemented, hence receiver fails.

这篇关于工厂模式:iBeacon代理没有被执行文件调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆