通知センターに気温と湿度を表示しようと思った。%を出そうと思ったら、どうやっても出ない。えー。
NSString *message = [NSString stringWithFormat:@"Temp %.1f℃, Humidity %d%% in %@",
[weather.temperatureC doubleValue],
[weather.humidity intValue], // これが表示されない
weather.locationName];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.alertBody = message;
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.alertAction = @"OPEN";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
ほら出ない!!!
フォーマット文字列内の湿度以降が欠けている。%
を正しく表示するにはUILocalNotification
のalertBody
に%%
を渡さなければいけないようだ。
このケースだとフォーマット文字列の結果が%%
にならなければいけないので、%%%%
を渡すことにする。
NSString *message = [NSString stringWithFormat:@"Temp %.1f℃, Humidity %d%%%% in %@",
[weather.temperatureC doubleValue],
[weather.humidity intValue],
weather.locationName];
ほらこれで大丈夫!
UILocalNotificationが%
を特殊文字として取り扱っているのかな?と思ったんですがドキュメントに何も書かれてないし、詳しい原因は良くわかりません。
参考