My app supports both LTR and RTL. It works fine for all cases. If i change app language from app settings then in every screen language is updated and works fine.
When i press share button in app. Below code is executed.Here i want to show share picker in my app's selected language. But it doesn't show it in my app's language.
let text = NSLocalizedString("I liked this view in app", comment: "")
// set up activity view controller
let activityViewController = UIActivityViewController(activityItems: [text, urls], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
// activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)`
I have tried below code to update share view language change but it didn't work.
if ( Language.currentLanguage == .arabic) {
activityViewController.accessibilityLanguage = "ar-SA"
}
else{
activityViewController.accessibilityLanguage = "en-US"
}
I have also tried below code but it is also not working.
if ( Language.currentLanguage == .arabic) {
activityViewController.view.semanticContentAttribute = .forceRightToLeft
}
else{
activityViewController.view.semanticContentAttribute = .forceLeftToRight
}
Anyone could help me with this issue ?
PS
For share picker you can refer below screenshot :
A solution which worked for me. Go to your Info.plist and add Localized resources can be mixed with Boolean YES or NO to it, and check the result.
As mentioned in Core Foundation Keys:
CFBundleAllowMixedLocalizations
CFBundleAllowMixedLocalizations (Boolean - iOS, macOS) specifies
whether the bundle supports the retrieval of localized strings from
frameworks. This key is used primarily by Foundation tools that link
to other system frameworks and want to retrieve localized resources
from those frameworks.
Related
I'm blocking screenshots and video records for ios in my app. But when I installed the latest update ios rejected it.
We noticed that your app shows a custom screenshot-initiated interface
when the user takes a screenshot, but the interface duplicates the iOS
system-provided screenshot interface and functionality.
Duplicating system-provided interfaces does not provide the simple,
innovative, and easy to use experience App Store users expect.
This is rejected message.
This is my code
extension UIWindow {
func makeSecure() {
let field = UITextField()
field.isSecureTextEntry = true
self.addSubview(field)
field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.first?.addSublayer(self.layer)
}
}
How to I solve it
Im trying to share a Instagram post from an app that I made in swiftUI using UIActivityView, but whenever I try to share it only the picture shows up and the caption doesn't. The same thing happens with Facebook.
func sharePost(){
isSheetShowing.toggle()
let caption = "Hello, world!"
if let image = UIImage(named: "Image") {
let vc = UIActivityViewController(activityItems: [image,caption], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(vc,animated : true)
}
}
UIActivityController needs to correctly recognize what exactly you are trying to share in order to display it corrrectly. This solution seems to answer your question directly.
Also, this is kind of an anti-pattern in SwiftUI (presenting it directly on the window). You should check this question out.
I have a problem with the above stated. I can not find the exact information on the forums. Most of them are outdated and I have written the code programmatically. I have a controller that contains a view to edit the profile. I can not access that after changing the function listed below. I have a rootviewcontroller set to something else, but I tried the UiApplication calls anyway and it return nil and I can not open the profile controller. This is the function listed below.
#objc func handleOpen2() {
(UIApplication.shared.keyWindow?.rootViewController as? BaseSlidingController)?.openMenu()
}
Xcode does not give me an error but I can not get my menu to open. My rootviewcontroller is set to something else in app delegate. I have a controller that is used to control the sliding menu when I press the edit profile button.
func openMenu() {
isMenuOpened = true
redViewLeadingConstraint.constant = menuWidth
redViewTrailingConstraint.constant = menuWidth
performAnimations()
setNeedsStatusBarAppearanceUpdate()
}
This code is used to open my side bar menu with the information I need and also to perform animations as well. I was wondering if someone had any idea what I can do different instead in my handleOpen2 function. If you need more code, please let me know. Thanks
On swift 5 version:
(UIApplication.shared.windows.first?.rootViewController as? BaseSlidingController)?.openMenu()
While clicking on the button , i am moving to another view controller using the following code.
var window: UIWindow?
window = UIWindow.init(frame: UIScreen.main.bounds)
window?.autoresizesSubviews = true
window?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let trackingViewController = LoginCameraViewController.init(screen:
.main)
window?.rootViewController = trackingViewController
window?.addSubview((trackingViewController?.view)!)
window?.makeKeyAndVisible()
window?.layoutSubviews()
For every button click, a new window is added to the application.I want to remove the latest window added.
The number of windows present in the application can be known by using following code.
let windowz = UIApplication.shared.windows
print("subviews",windowz)
I think you get the wrong concept of navigation in iOS. Window is like a root object in which ViewControllers appear. So probably the solution you're looking in a first place is UINavigationController.
Apple Documentation on Navigation
For iOS 13 i was able to do it this way
I created array which contains the window using which this new viewController is being presented,
var arrWindow = [UIWindow]()
arrWindow.append(yourNewWindow)
// Note: This will be stored as strong reference so need to remove it.
Also store your original window in variable
let originalWindow = yourOriginalWindow
// Note: Same goes for this as well ,this will be stored as strong reference so need to remove it.
At the time of removing there are many ways to do it but this was the most suited way for me,
func removeAppendedWindow() {
for window in arrWindow {
if window != originalWindow {
if let index = arrWindow.index(of: window) {
window.isHidden = true
arrWindow.remove(at: index)
}
}
}
}
In the below code windowz is normal array.
let windowz = UIApplication.shared.windows
You can remove last by using
windowz.removeLast()
You should use View Controller instead of adding windows and pop it instead where you are removing the window.
Window is only one object for app and will contain the views.
Please correct your understanding and use View controllers.
I'm trying to implement google's placepicker for ios.
There is some demo code at:
https://github.com/googlemaps/maps-sdk-for-ios-samples/tree/master/GooglePlacePicker/GooglePlacePickerDemos
And i get most of it except the line in the file PickAPlaceViewController.swift
var mapViewController: BackgroundMapViewController?
In the github repo Google have provided their own class BackgroundMapViewController.
Do I need to create an instance of this class to use the place picker?
Or can I just use a GMSMapView like I ordinarily would with google maps.
Thanks.
For Google Places Controller you just need below code to show or present Places Controller in your App.
Put this in ur Button Action method :
// Create a place picker. Attempt to display it as a popover if we are on a device which
// supports popovers.
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
placePicker.modalPresentationStyle = .popover
placePicker.popoverPresentationController?.sourceView = pickAPlaceButton
placePicker.popoverPresentationController?.sourceRect = pickAPlaceButton.bounds
// Display the place picker. This will call the delegate methods defined below when the user
// has made a selection.
self.present(placePicker, animated: true, completion: nil)
Hope This will helps to show Place Picker in your app.