I am adding local notifications to my current project and I noticed something weird. What I am doing is displaying warnings when a piece of hardware has a low battery. When the app is in the foreground (and I replace the notification with an alert view) the string displays fine. However when the app is in the background my percentile sign disappears.
@"%@ has less than %i%% battery left!"
is the string that I am using. In the alert view it will display something like "X has less than 10% battery left!" but the background notification displays "X has less than 10battery left!"
Has anyone encountered that before?
edit (adding code snippet)
UILocalNotification *lc = [[UILocalNotification alloc] init];
lc.fireDate = [[NSDate alloc]init];
lc.alertBody = [NSString stringWithFormat:@"%@ has less than %i%% battery left!", name, percentage];
lc.timeZone = [NSTimeZone defaultTimeZone];
lc.applicationIconBadgeNumber = lc.applicationIconBadgeNumber + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:lc];
Where name is a NSString and percentage is an int
I found out that using the unicode character equivalent will make it work in both the alert view and notification. I changed my string to:
@"%@ has less than %i\uFF05 battery left!"
However, I'd still like to know why escaping doesn't work on a local notification.
I have reproduced the issue in my simulator also and also I fixed the issue.
Use:
@"%@ has less than %i %%%% battery left!"
or
[NSString stringWithFormat:@"%@ has less than %i %@ battery left!",@"Your App",7,@"%%"]
Instead of:
@"%@ has less than %i%% battery left!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With