1

I am trying to add a tile with code from the MSBand documentation.

EDIT: I never get the log output from these 2lines:
NSLog(@"adding tile...");
if(error)NSLog(@"error adding tile to band: %@", error);
, which i find very odd

 NSError *error;
MSBIcon *smallIcon = [MSBIcon iconWithUIImage:[UIImage imageNamed:@"MSB_white_x"] error:&error];
if(error)NSLog(@"small icon error: %@", error);

MSBIcon *tilecon = [MSBIcon iconWithUIImage:[UIImage imageNamed:@"MSB_white_xx"] error:&error];
if(error)NSLog(@"big icon error: %@", error);

NSUUID *tileID = [NSUUID UUID];
MSBTile *tile = [MSBTile tileWithId:tileID name:@"Something" tileIcon:tilecon smallIcon:smallIcon error:&error];
if(error)NSLog(@"tile creation error: %@", error);
[self.sensor.client.tileManager addTile:tile completionHandler:^(NSError *error) {
    NSLog(@"adding tile...");
    if(error)NSLog(@"error adding tile to band: %@", error);
}];

But when I try to run the app I get the following warning:

Warning: Attempt to present MSBAddTileDialogViewController_iOS: 0x14f534e20 on PersonalStatisticsViewController: 0x14f5116b0 whose view is not in the window hierarchy!

I noticed that the "on view controller" is always the root view controller regardless. Hence when I first got the warning from within another view controller than root I tried changing the root to whatever VC i was currently in. I run the code from -()viewDidAppear I really don't understand why I get this warning, mainly because I see no reason for the tile-creation to try and add anything to the app VCs (it should just add the tile to the MSBAND).

Does anybody have any idea whats going on? Thanks in advance.

DevilInDisguise
  • 360
  • 1
  • 4
  • 14
  • When a 3rd party app attempts to add a tile to the users band the Microsoft Band SDK presents a dialog (modal view) to ask the user if it should proceed with the install request from the 3rd party app. If the addTile is called from a view that has not been inserted into the view hierarchy then you will see this error. – Mark Thistle May 04 '15 at 21:34
  • @MarkThistle if i try to run the addTile function from within a dispatch_sync it blocks the whole app. I suspect this might be the reason, because I noticed that add tile on some occasion fails, but does so later that the following calls (hence i want to dispatch it sync.) – DevilInDisguise May 21 '15 at 16:19
  • A dispatch_sync will block the app as expected for dispatch_sync. If you are not seeing the NSLog(@"adding tile..."); call then have you checked that none of the objects in the self.sensor.client.tileManager are nil? In Objective-C if an object is nil then any call to it is a no-op. It does not crash the app due to a nil pointer in other words. So, I would verify that the self.sensor.client.tileManager objects are not nil. – Mark Thistle May 21 '15 at 21:17

1 Answers1

0

Where are you making the addTile call from?

If you are calling from in the viewDidLoad then you will see this problem. You should move your addTile call into viewDidAppear.

Reference this StackOverflow question: whose view is not in the window hierarchy

Community
  • 1
  • 1
Mark Thistle
  • 1,871
  • 14
  • 21
  • sry for late reply. I make the call from viewDidAppear already as stated in post. One thing that strike me is that through my testing I never stumbled upon any dialogs presented? Another thing that I find odd, is that its the "root view controller," that "is not presented." If i set another vc as "initial root" that vc will be the problem not being presented. I did try to run the code from within viewdidappear in the vc that was set to root at the time. – DevilInDisguise May 20 '15 at 17:29
  • i made an edit, i dk why but this seems odd that addTile wouldn't work right. – DevilInDisguise May 21 '15 at 15:46