Notification Service Extensions with NSLocalizedString
Asked Answered
A

1

5

I am using Notification Serivce Extension to change the text coming from the server as per what I Want.

However, that was working good with normal strings. but when I used NSLocalizedString with it, it dosent show the localized string, instead it shows the field name of the string.

For example: inside the UNNotificationServiceExtension:

let CompanyViewLM = NSLocalizedString("Notifications.View", comment: "No Comment")

and in Localizable.strings I put the following line:

Notifications.View = "I Viewed your profile";

Noting that I put the same lines of code in a normal view controller and it works just fine.

Ahl answered 6/7, 2017 at 16:1 Comment(1)
I have the opposite problem. The base development language (English) is not being displayed correctly by NSLocalizedString but my localized languages are displayed correctly (French, Spanish). Any thoughts?Caisson
A
11

I Found by my self what was the problem. The notification service target was working in the project without recognizing other files of the project.

To make it recognizes other files you must go to targets -> NotificationService -> Copy Bundle Resources -> add the files you want the notification service to work with.

In my case, I added the Localizable.strings file and it worked as a charm.

Ahl answered 6/7, 2017 at 17:14 Comment(6)
will it work for multiple language. suppose my app language is arabic but phone language is english. can we display alert in arabic languageProvocative
Yes we can using the notification service. We can change the text as what we want.Ahl
how it will get app language as my app is terminated when receive pushProvocative
Your App must not terminated when receiving push notification , Instead it will receive it and you will have a function to modify it and then you will present it.Ahl
yes that is the question my app has arabic language if user selected arabic and terminate app (device language is english) it only display push in english it should display in arabic. is there any way ?Provocative
There are many ways, before terminating the application you must set the application language first, then if you are using firebase notifications for example , you can send additional data with your notification and not only in aps parameter (See iOS Notification structure), pass English & Arabic texts on it, and depending in application language present the suitable text, If you are using azure for notifications , there is more easy way to do that , you can make a new notification registration with required language and done.Ahl

© 2022 - 2024 — McMap. All rights reserved.