2014-10-02 19 views
0

我正在爲iBeacons使用ESTimote SDK,並且您可以在其示例中調用自定義init方法。不過,我正在使用故事板,故事板不會調用我的自定義init方法。所以客戶支持建議我將自定義init方法移到viewDidLoad中,但我似乎無法弄清楚。當使用自定義init方法時,當前區域爲空。如果我硬編碼的UUID,主要和次要的它很好。用於iBeacon的viewDidLoad中的自定義初始化

-(id)initWithBeacon:(ESTBeacon *)beacon 
{ 
    self = [super init]; 
    if (self) 
    { 
     self.beacon = beacon; 
     NSLog(@"Initiation got called"); 
    } 
    return self; 
} 



- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"B9407f30-f5f8-466e-aff9-25556b57fe6d"]; 

    self.beacon = [[ESTBeacon alloc] init]; 
    self.beaconManager = [[ESTBeaconManager alloc] init]; 
    self.beaconManager.delegate = self; 
    self.beacon = _beacon; 
    self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:uuid 
                   major:37470 
                   minor:56023 
                  identifier:@"RegionIdentifier"]; 

    self.secondBeaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:self.beacon.proximityUUID 
                   major:[self.beacon.major unsignedIntValue] 
                   minor:[self.beacon.minor unsignedIntValue] 
                  identifier:@"RangingRegion"]; 

    if (self.beaconRegion) { 
     NSLog(@"youve got your region"); 
    } 

    if (self.secondBeaconRegion) { 
     NSLog(@"the second beacon region"); 
    }else{ 
     NSLog(@"the second region doesnt get intialized "); 
    } 

    self.beaconRegion.notifyOnEntry = YES; 
    self.beaconRegion.notifyOnExit = YES; 

    [self.beaconManager startMonitoringForRegion:self.beaconRegion]; 
    [self.beaconManager startRangingBeaconsInRegion:self.secondBeaconRegion]; 
    [self.beaconManager requestAlwaysAuthorization]; 
} 
+0

該視圖是如何被調用的? init之前存儲的信標實例在哪裏? – brandonscript 2014-10-02 13:35:44

回答

0

如果您使用故事板,則會調用其他構造函數。 XIB和Storyboard使用initWithCoder:(NSCoder*)aDecoder構造函數。

如果您想將信標傳遞給您的控制器,那麼您需要在繼續期間傳遞信標。見Apple's docs