简体   繁体   中英

Adding variable to LocatNotification error is Property access result unused - getters should not be used for side effects

Trying to understand how to insert a variable in the .alertBody portion of a local notification. the cell.deviceNameLabel.class is what I want to be inserted. I do not know how this is done. The local notification works if I use plain text.

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  static NSString *CellIdentifier = @"MyReusableCell";
  SightingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell != nil) {
      Device *device = [self.transmitters objectAtIndex:indexPath.row];

      // Update the device text
     cell.deviceNameLabel.text = device.name;

     // Update the device avatar (icon image)
     NSInteger avatarID = [UserSettingsRepository getAvatarIDForTransmitterID:device.identifier];
     NSString *imageFilename = [NSString stringWithFormat:@"avatar_%02ld.png", (long)avatarID];
     cell.transmitterIcon.image = [UIImage imageNamed:imageFilename];

     if ([self isTransmitterAgedOut:device]) {
         [self grayOutSightingsCell:cell];
         //Add Local Notification
         NSDate *AlertTime = [[NSDate date] dateByAddingTimeInterval:3];
         UIApplication *app = [UIApplication sharedApplication];
                               UILocalNotification *notifyAlert = [[UILocalNotification alloc] init];
                               if (notifyAlert) {
                                   notifyAlert.timeZone = [NSTimeZone defaultTimeZone];
                                   notifyAlert.repeatInterval = 0;
                                   notifyAlert.soundName = @"soundeffect.mp3";
                                   notifyAlert.alertBody = @"%@ went out of range", cell.deviceNameLabel.class;
                                   notifyAlert.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
                                   [app scheduleLocalNotification:notifyAlert];
                                    }
     } else {
         [self updateSightingsCell:cell withTransmitter:device];
     }
 }
 return cell;

采用:

[NSString stringWithFormat:@"%@ went out of range", NSStringFromClass(cell.deviceNameLabel.class);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM