I am looking for a way how to format text of alertBody
of UILocalNotification
. I noticed that for example mail app sets first line from Subject and second and third lines are preview of email body. If subject is longer than 1 line, it is truncated. This works correctly with dynamic font, so no matter what text size is set in accessibility.
I tried to do achieve same result, but with no success.
What I tried
sizeWithAttributes
while using preferedFontForTextStyle
All these solutions partially work, but for some text size/device will fail
What I am looking for is an approach to get lock screen's notification font name, size, kerning or any other parameters neccessary to be able to properly set UILocalNotification.alertBody
as only 1 line of text on any iOS device with any text size accessibility setting.
I am aware that these properties may be different for different iOS version, but iOS8 is enough for me.
Thank you
The closest you are going to get to is a guess. You can use
"\n"
to enforce a carriage return, but you won't know for sure when to use it.
There is no iOS support to let you tell, ahead of time, what is the screen size or orientation your notification will arrive.
You are up against the banner:
Banners do not display localNotification.alertTitle
Then up against the clock, so to speak:
You create notifications ahead of time. The fact that they are local is no reason to know what the future will hold: for all you know, you may be scheduling 1 month from now, and the user may have updated the OS, causing new fonts or layout constraints to apply.
In other words, the answer to this question is: You need to work for Apple Computer and get a local callback prior the notification is displayed, which is, as of date, not an option..
Conclusion
Use short alertTitle
, short alertBody
, possibly sprinkled here and there with \n
to force new lines.
// Use '\n' to force newline
localNotification.alertBody = "Alert fired.\nWas set for ..."
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