尝试了解如何在本地通知的.alertBody部分插入变量。我希望插入cell.deviceNameLabel.class。我不知道这是怎么做的。如果我使用纯文本,则本地通知有效。
- (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;
答案 0 :(得分:0)
使用:
[NSString stringWithFormat:@"%@ went out of range", NSStringFromClass(cell.deviceNameLabel.class);