Text format UILocalNotification.alertBody

I am looking for a way to format alertBody text from UILocalNotification . I noticed that, for example, email applications install the first line of the subject, and the second and third lines are viewing the body of the email. If an object is longer than 1 line, it is truncated. This works correctly with a dynamic font, so no matter what size of the text is set in the accessibility. I tried to achieve the same result, but without success.

What i tried

  • Cut the string to a specific length
  • Getting row size using sizeWithAttributes when using preferedFontForTextStyle

All of these solutions partially work, but for some text / device size it will fail

What I'm looking for is an approach that allows me to get the name, size, kerning or any other parameters of the name of the screen lock screen in order to be able to correctly set UILocalNotification.alertBody as soon as 1 line of text on any iOS device with any size of accessibility text.

I know that these properties may vary for different versions of iOS, but iOS8 is enough for me.

thanks

+5
source share
2 answers

Let the OS do the layout

Closest you are going to guess. you can use

 "\n" 

to provide a carriage return, but you won’t know for sure when to use it.

There is no iOS support to tell you in advance what screen size or orientation of your notification is.

You are against the banner:

Banners do not display localNotification.alertTitle

2 notification banners, portrait and landscape

Then counterclockwise, so to speak:

You create notifications in advance. The fact that they are local is not a reason to know what will happen in the future: for everything that you know, you can plan in 1 month and the user can update the OS, as a result of which new fonts will be applied or layout restrictions.

In other words, the answer to this question is: You need to work on Apple Computer and get a local callback before a notification is displayed, which is not an option from the date.

Notification center


Conclusion

Use a short alertTitle , a short alertBody , possibly sprinkled here and there with \n to create new lines.

 // Use '\n' to force newline localNotification.alertBody = "Alert fired.\nWas set for ..." 
+3
source

The first line of mailbox applications is the alertTitle property, recently introduced> = iOS 8.2 2015-03-09 See here .

Use this property to provide a brief description of the reason for the warning. You can specify a string with the text you want to display, or specify a string that will be used as a search key in the localization files Localizable.strings. The default value of this property is nil.

The title lines should be short, usually just a few words describing the reason for the notification. Apple Watch displays a title bar as part of the short preview notification interface, which has limited space.

For the second note, all alertBody notification alertBody are truncated, depending on the length. The notification displays only so many characters, which corresponds to the height of UILocalNotification . However, no matter what size, if you clear the notification, it will display the remaining characters, if any, in the same way as the App. You can shorten your alertBody with any method that works for you , but as far as formatting it in terms of UIAppearance protocols, there is no Apple approved method

0
source

All Articles