iOS background view not updated using NSTimer while scanning the bluetooth DEVICE -


i trying work on getting bluetooth scanning page pair ble device using bluetooth. have found nsuinteger [ _ble.scannedperipheral count ] change while scanning. however, when comes execution, background view images , pages cannot change. please tell me other wayout make page change if variable showing available ble devices changes 0 1,2 or 3 ?

the below code : (only relevant)

- (void)viewdidappear:(bool)animated {     if (_ble)     {         _ble.delegate = (id) self;         _ble.btstatus = bt_idle;         [_ble startscanning];     }      [nstimer scheduledtimerwithtimeinterval:0.2f  target:self selector:@selector(reloaddata) userinfo:nil repeats:yes];  }   -(void) reloaddata {       dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         // time consuming workout             dispatch_async(dispatch_get_main_queue(), ^{             // ui update workout bluetooth scanning              if( [ _ble.scannedperipheral count ] > 0 ){                 [self stopanimatingimages];                 [self settapdemo :  [uiimage imagenamed:@"pairing_d.png"]  : @"pairing"  : @"#c4cccf"] ;             }else{                 [self settapdemo : [self loadingimage] : @"pairing"  : @"#c4cccf"] ;                 [self animateimages];             }         });     }); }     - (void) settapdemo: (uiimage *) cover  : (nsstring *) title : (nsstring *) colorhex{      image = [uiimage imagenamed:@"shaded_cal.png"];     imagea = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];     _container = [[uiview alloc] initwithframe:[self.view bounds]];     [imagea setimage:cover];     imagea.userinteractionenabled = yes;     uitapgesturerecognizer *mygesture = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(touchesbegan:)];     mygesture.numberoftapsrequired = 1;     mygesture.delegate=self;     [imagea addgesturerecognizer:mygesture];     [imagea setcontentmode:uiviewcontentmodescaleaspectfill];      mylabelq = [self constructlabelt:title:0.27:0.08: colorhex:25];     mylabelback =[self constructlabelt:@"back":0.04:0.01:@"#c4cccf":18] ;     if( blecount > 0){           for(nsuinteger  = 0 ; < [ _ble.scannedperipheral count ] ; ++){             deviceperiperal *device;             nsstring *uuid = [_ble.scannedperipheralkey objectatindex:i];              nslog (@"device uuid = %@",  uuid);              if (uuid)              {                  device = [_ble.scannedperipheral objectforkey:uuid];                  nsdata * ssx = device.advertdata ;                  device.rowindex = i;                  nslog (@"device advert = %@",  ssx);                  if([ssx length] > 0){                      nsdata *macd = [ssx subdatawithrange:nsmakerange(0, 6)];                      nsdata *paird = [ssx subdatawithrange:nsmakerange(6, 1)];                      nsstring* newstr =  [self hexrepresentationwithspaces:paird : no];                      nsstring* newmac =  [self hexrepresentationwithspaces:macd : yes];                      nslog (@"newstr = %@", newstr );                      nslog (@"newmac = %@", newmac );                      _checksumbyte = [self calculatechecksum:newmac];                  }                   nslog (@"device = %@", device.uuid);                  if (device )                  {                      uiimage *dimage = [uiimage imagenamed:@"device_u.png"];                      float change =  0.15*i;                      float yposition = 0.25 + change ;                      [imagea addsubview:[self deviceget:dimage:device.devicename: 0.40 : yposition : @"#c4cccf"]];                  }              }           }          //uiimage *dimage = [uiimage imagenamed:@"device_u.png"];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.25 : @"#c4cccf"]];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.40 : @"#c4cccf"]];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.55 : @"#c4cccf"]];          //[imagea addsubview:mylabels3];           mylabels1 = [self constructlabelt:@"spotted":0.27:0.723: colorhex:25];          mylabels2 =[self constructlabelt:@"(choose 1 want connect)":0.55:0.76:@"#c4cccf":10] ;          mylabels3 = [self constructlabelt:@"devices":0.30:0.76: colorhex:25];       }else{           mylabels1 = [self constructlabelt:@"scanning":0.27:0.723: colorhex:25];          mylabels2 =[self constructlabelt:@"devices":0.51:0.76:@"#c4cccf":25] ;          mylabels3 = [self constructlabelt:@"for":0.30:0.76: colorhex:25];      }      [imagea addsubview:mylabelq];     [imagea addsubview:mylabelback];      [imagea addsubview:mylabels1];     [imagea addsubview:mylabels2];      [imagea addsubview:mylabels3];     [_container addsubview:imagea];      [self.view addsubview:_container];     [self.view sendsubviewtoback:_container];  } 

each time call settapdemo :::, create new _container view , added self.view . because never remove old 1 super view before initialise again, self.view contains more , more subviews timer repeats consume memory app crash.

further, [self.view sendsubviewtoback:_container] called each time while timer fired, , never remove old _container, new _container hidden behind result.

in conclusion, guess did create updated _container while [ _ble.scannedperipheral count ] changed staying behind other subviews. may try modify code this:

- (void) settapdemo: (uiimage *) cover  : (nsstring *) title : (nsstring *) colorhex{      // remove old _container view     if (_container) [_container removefromsuperview];          image = [uiimage imagenamed:@"shaded_cal.png"];     imagea = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];     _container = [[uiview alloc] initwithframe:[self.view bounds]];     [imagea setimage:cover];     imagea.userinteractionenabled = yes;     uitapgesturerecognizer *mygesture = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(touchesbegan:)];     mygesture.numberoftapsrequired = 1;     mygesture.delegate=self;     [imagea addgesturerecognizer:mygesture];     [imagea setcontentmode:uiviewcontentmodescaleaspectfill];      mylabelq = [self constructlabelt:title:0.27:0.08: colorhex:25];     mylabelback =[self constructlabelt:@"back":0.04:0.01:@"#c4cccf":18] ;     if( blecount > 0){           for(nsuinteger  = 0 ; < [ _ble.scannedperipheral count ] ; ++){             deviceperiperal *device;             nsstring *uuid = [_ble.scannedperipheralkey objectatindex:i];              nslog (@"device uuid = %@",  uuid);              if (uuid)              {                  device = [_ble.scannedperipheral objectforkey:uuid];                  nsdata * ssx = device.advertdata ;                  device.rowindex = i;                  nslog (@"device advert = %@",  ssx);                  if([ssx length] > 0){                      nsdata *macd = [ssx subdatawithrange:nsmakerange(0, 6)];                      nsdata *paird = [ssx subdatawithrange:nsmakerange(6, 1)];                      nsstring* newstr =  [self hexrepresentationwithspaces:paird : no];                      nsstring* newmac =  [self hexrepresentationwithspaces:macd : yes];                      nslog (@"newstr = %@", newstr );                      nslog (@"newmac = %@", newmac );                      _checksumbyte = [self calculatechecksum:newmac];                  }                   nslog (@"device = %@", device.uuid);                  if (device )                  {                      uiimage *dimage = [uiimage imagenamed:@"device_u.png"];                      float change =  0.15*i;                      float yposition = 0.25 + change ;                      [imagea addsubview:[self deviceget:dimage:device.devicename: 0.40 : yposition : @"#c4cccf"]];                  }              }           }          //uiimage *dimage = [uiimage imagenamed:@"device_u.png"];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.25 : @"#c4cccf"]];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.40 : @"#c4cccf"]];          //[imagea addsubview:[self deviceget:dimage:@"x": 0.40 : 0.55 : @"#c4cccf"]];          //[imagea addsubview:mylabels3];           mylabels1 = [self constructlabelt:@"spotted":0.27:0.723: colorhex:25];          mylabels2 =[self constructlabelt:@"(choose 1 want connect)":0.55:0.76:@"#c4cccf":10] ;          mylabels3 = [self constructlabelt:@"devices":0.30:0.76: colorhex:25];       }else{           mylabels1 = [self constructlabelt:@"scanning":0.27:0.723: colorhex:25];          mylabels2 =[self constructlabelt:@"devices":0.51:0.76:@"#c4cccf":25] ;          mylabels3 = [self constructlabelt:@"for":0.30:0.76: colorhex:25];      }      [imagea addsubview:mylabelq];     [imagea addsubview:mylabelback];      [imagea addsubview:mylabels1];     [imagea addsubview:mylabels2];      [imagea addsubview:mylabels3];     [_container addsubview:imagea];      //[self.view addsubview:_container];     //[self.view sendsubviewtoback:_container];     // 1 line of code can trick      [self.view insertsubview:_container atindex:0]; } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -