UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How can i restart a SwiftUI application programmatically ?

Forums > SwiftUI

Hi every one,

Please how can i restart a SwiftUI application programmaticlly ?

Thanks.

3      

You cant.

3      

@twostraws  Site AdminHWS+

Yeah, this is definitely a hard no – you shouldn't attempt to stop or start apps.

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

I am curious to learn what problem you have that you are trying to solve by restarting your app.

3      

@nemecek-filip , @twostraws thanks for your replies. :)

@PointOfNilReturn i appreciate your curiosity MAN :) The problem is about localization. Some one told me to use Application setting url so the user could click on language and then chosing among the available languages. what i see in this solution is making the user to pass by many pages just to change the language and has to click on back button to go to the app. this solution is changing the language on the fly but it's really useless for givving the best user experience. I decided to go by the second way where i change the language setting in the UserDefaults and asking the user to close and start the application to apply changes.

As you can see i just would to restart the application programaticly instead of asking the user to do that manually.

Please if there is a better solution for changing the app language i'll be thankfull for it.

Best regards.

3      

I think it was me who suggested the solution. But maybe I wasnt clear. The URL wont just launch the iOS Settings app, it will launch it and navigate to the section with settings for your app. Here user will select new language, tap the back button in top left corner and the app will be re-launched with new language.

I dont think this is asking much from users and I dont think many will decide to change the language anyway.

3      

@nemecek-filip yep you're right, it was your solution but believe me in the current project the user will prefer to restart the app manually instead of going throught another pages just to change the language on the fly. The users of the current project are insisting on the easy of use and less navigations, that's why i would to let the app restart automaticly instead of asking the user to do that manually.

Please if there is a better way to change the language on the fly without requesting the restart or going throught other views, it will be the perfect solution for them. Their requirement is changing the language only by a single click of button.

kind regards.

3      

In that case you need to manually implement language selection in your app and manually get the correct localization strings based on the selected language.

After user selects new language, you can use something like NotificationCenter.default to post notification and update texts across your app.

3      

@nemecek-filip yep i already made 2 buttons for the 2 differents languages and when the user clicks on one i change the settings (in UserDefaults) and request user for restarting the app. I really would like to know how i can implement your suggested solution, please can you give a hintor a link.

Kind rgards.

3      

I have no idea how you are setting localization texts in the first place. But you need to do it again after the user switches language. This way you dont have to force the user to restart the app.

3      

Hi again dear @nemecek-filip, i'm just puting the below single line in the "English" button action then i give a message to the user for asking him to close and start the application again.

                                UserDefaults.standard.set(["en"], forKey: "AppleLanguages")

Kind regards.

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.