objective c - Beacon Crash in IOS 10 -


anyone please fix "beacon crashing in ios10". didrangebeacons delegate method returns beacons array nil , code follows

   -(void)locationmanager:(cllocationmanager *)manager didrangebeacons:(nsarray *)beacons inregion:(clbeaconregion *)region {      @try {          clbeacon *beacon = [[clbeacon alloc] init];          nslog(@"beacons count %lu", (unsigned long)beacons.count);       if(beacons != nil && beacons != nil && beacons != null && beacons.count > 0) {          beacon = [beacons firstobject];      self.currentmajor = beacon.major;     self.currentminor = beacon.minor;      nsarray *majorminorids = [[nsarray alloc]initwithobjects:self.currentmajor,self.currentminor, nil];     self.comaseparatedids  = [majorminorids componentsjoinedbystring:@","];      /* log */     [self printlog:[nsstring stringwithformat:@"current major id: %@, previous major id: %@, current minor id: %@, previous minor id %@", self.currentmajor, self.prevmajor, self.currentminor, self.prevminor]];      // make web service request if new beacon detected     if((([self.prevmajor intvalue]!=[self.currentmajor intvalue]) || ([self.prevminor intvalue]!=[self.currentminor intvalue])) || (self.enteredregionnow))     {         nslog(@"making url request when new beacon detected");         // delete urls before calling web service         self.url_immediate = nil;         self.url_near = nil;         self.url_far = nil;         self.url_exit = nil;          // make web service request server         nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"http://ibeacon.bpsqr.me/geturls/?uuid=%@&minorid=%@&majorid=%@", [[nsuserdefaults standarduserdefaults] objectforkey:@"uuid"], self.currentminor, self.currentmajor]]];         self.urlsrequestconnection = [[nsurlconnection alloc] initwithrequest:request delegate:self];          self.prevmajor = self.currentmajor;         self.prevminor = self.currentminor;          self.enteredregionnow = false;           return;     }      // assigning beacon's current proximity     self.currentproximity = beacon.proximity;     [self printlog:[nsstring stringwithformat:@"current proximity : %d", self.currentproximity]];     [self printlog:[nsstring stringwithformat:@"previous proximity : %d", self.prevproximity]];     [self printlog:[nsstring stringwithformat:@"last visited webpage proximity : %d", self.previousproximitytag]];      // send notification based on notification enabled flag, proximity , url found in response     if([self.notificationenabled isequaltostring:@"true"])     {           double days =  [self diffbetweencurrentandnotificationdate];         nslog(@"days notification %f",days);          nsnumber *notificationduration =[[nsuserdefaults standarduserdefaults] objectforkey:@"notificationduration"];         nslog(@"notification duration plist %f",[notificationduration doublevalue]);           if (days >=[notificationduration doublevalue] || days == 0 ) {              nslog(@"hit count become 0 in differenecebetweencurrentandnotificationdate");              hitcount = 0 ;         }          switch (beacon.proximity) {              case clproximityunknown:                 // nothing                 break;              case clproximityimmediate:                 if(self.url_immediate != nil)                 {                         [self sendlocalpushnotification];                         self.notificationenabled = false;                    }                 break;              case clproximitynear:                 if(self.url_near != nil)                 {                         [self sendlocalpushnotification];                         self.notificationenabled = false;                   }                 break;              case clproximityfar:                 if(self.url_far != nil)                 {                         [self sendlocalpushnotification];                         self.notificationenabled = false;                   }                 break;              default:                 break;         }      }      // open web page based on proximity when general beacons(not notification beacon) detected     if([self.status_code isequaltostring:@"200"])     {         // not open web page while app in background         uiapplicationstate appstate = [[uiapplication sharedapplication] applicationstate];         if((appstate != uiapplicationstatebackground) && (appstate != uiapplicationstateinactive))         {             if (beacon.proximity == clproximityunknown) {                 if(self.currentproximity != self.prevproximity)                 {                     self.prevproximity = self.currentproximity;                 }                  /* log */                 [self printlog:@"unknown proximity"];             }             else if (beacon.proximity == clproximityimmediate) {                  if((self.currentproximity != self.prevproximity) && (![self.current_url isequaltostring:self.url_immediate]))                 {                     if(self.currentproximity == self.previousproximitytag)                     {                         self.previousproximitytag = self.prevproximity;                          if(self.flag_immediate == true)                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:20 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:1] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                                 [self performselector:@selector(openwebview:) withobject:self.url_immediate afterdelay:20.0];                             }                         }                         else                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:1] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                                 [self performselector:@selector(openwebview:) withobject:self.url_immediate afterdelay:3.0];                             }                         }                     }                     else                     {                         self.previousproximitytag = self.prevproximity;                          if(navcontroller != null)                         {                             [self stoptimertask:self.timer_short];                             self.timer_short = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:1] repeats:no];                         }                         else                         {                             [self performselector:@selector(openwebview:) withobject:self.url_immediate afterdelay:0.0];                         }                     }                     self.prevproximity = self.currentproximity;                 }                 else if ([self.current_url isequaltostring:self.url_immediate])                 {                     self.prevproximity = self.currentproximity;                 }                 /* log */                 [self printlog:@"immediate"];             }             else if (beacon.proximity == clproximitynear) {                  if((self.currentproximity != self.prevproximity) && (![self.current_url isequaltostring:self.url_near]))                 {                     if(self.currentproximity == self.previousproximitytag)                     {                         self.previousproximitytag = self.prevproximity;                          if(self.flag_near == true)                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:20 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:2] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                                 [self performselector:@selector(openwebview:) withobject:self.url_near afterdelay:20.0];                             }                         }                         else                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:2] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                                 [self performselector:@selector(openwebview:) withobject:self.url_near afterdelay:3.0];                             }                         }                     }                     else                     {                         self.previousproximitytag = self.prevproximity;                          if(navcontroller != null)                         {                             [self stoptimertask:self.timer_short];                             self.timer_short = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:2] repeats:no];                         }                         else                         {                             [self performselector:@selector(openwebview:) withobject:self.url_near afterdelay:0.0];                         }                     }                     self.prevproximity = self.currentproximity;                 }                 else if ([self.current_url isequaltostring:self.url_near])                 {                     self.prevproximity = self.currentproximity;                 }                 /* log */                 [self printlog:@"near"];             }             else if (beacon.proximity == clproximityfar) {                  if((self.currentproximity != self.prevproximity) && (![self.current_url isequaltostring:self.url_far]))                 {                     if(self.currentproximity == self.previousproximitytag)                     {                         self.previousproximitytag = self.prevproximity;                          if(self.flag_far == true)                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:20 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:3] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                              //   [self savefarbeaconproximitymessage];                                  [self performselector:@selector(openwebview:) withobject:self.url_far afterdelay:20.0];                             }                         }                         else                         {                             if(navcontroller != null)                             {                                 [self stoptimertask:self.timer_long];                                 self.timer_long = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(x:) userinfo:[nsnumber numberwithint:3] repeats:no];                             }                             else                             {                                 [self stopperformselectortask];                               //  [self savefarbeaconproximitymessage];                                  [self performselector:@selector(openwebview:) withobject:self.url_far afterdelay:3.0];                             }                         }                     }                     else                     {                         self.previousproximitytag = self.prevproximity;                          if(navcontroller != null)                         {                             [self stoptimertask:self.timer_short];                             self.timer_short = [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(showalertonproximitychange:) userinfo:[nsnumber numberwithint:3] repeats:no];                         }                         else                         {                           //  [self savefarbeaconproximitymessage];                              [self performselector:@selector(openwebview:) withobject:self.url_far afterdelay:0.0];                         }                     }                     self.prevproximity = self.currentproximity;                 }                 else if ([self.current_url isequaltostring:self.url_far])                 {                      self.prevproximity = self.currentproximity;                 }                 /* log */ //                  [self savefarbeaconproximitymessage];                  [self printlog:@"far"];             }         }      }  } else {     [self printlog:@"beacon nil"];     return; }      }     @catch (nsexception *exception) { //        <#handle exception thrown in @try block#>     }     @finally { //        <#code gets executed whether or not exception thrown#>     }   } 

bluetooth enabled in device, have tried changing deployment target specified in following link ranging beacons in ios 10. , array nil conditions checked, entire code enclosed try catch in objective c though app crashing saying "beacon array nil". ios10 support beacon ? in advance help.

there number of anecdotal reports of beacon detection problems on ios 10, users reporting setting app deployment target in xcode 9.x resolve issue. see here details:

https://stackoverflow.com/a/39641127/1461050


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -