Post

Replies

Boosts

Views

Activity

Is there a way to pretend IP address in Xcode Device Simulator?
Hi Apple Developers, I am integrating a 3rd SDK into my app, and this SDK is expected to behave differently if the device is in Europe. However, I am not in Europe, such that I cannot directly test its behaviour in Europe. This SDK decides the device location by IP address, so I think if there is a way to assign a "pretend" IP address to the simulated iPhones in Xcode device simulator, then I should be able to see how the app behaves. Do you know any way to do that? Thank you! Some detail information: the 3rd party SDK I tried to test with is MoPub SDK. Its GDPR consent part uses the IP address. As shown in the screenshot below. I also have tried "pretend" location through schema editing from Xcode. The location was altered in the simulated device but I still cannot see the GDPR consent message since IP address is not changed.
3
0
1.1k
Sep ’21
Xcode: Why I need #available(iOS 14.0, *) even if the project iOS Deployment Target is 14.1?
Hi! Apple Developers, I am trying to simplify the code of a project to support only iOS 14.1 or above, such that I remove the unnecessary logic the checks the iOS versions from the code, as well as the code branches that only works for iOS13.X or earlier. However, even if I changed the project's iOS Development Target to 14.1 (as the screenshot below), Xcode will still return compiling error when I delete some *#available(iOS 14.0, ) logic. I tried to change the following code to below, without the #available logic, Xcode will return error saying 'status' is only available in iOS 14.0 or newer. Some more details: I am using up-to-date Xcode 12 the project is integrated with some pods with Cocoapods. I also changed the iOS Deployment Target of the Pods project to 14.1. The project uses the old interface builder for UI, not SwiftUI What else do I need to do, such that I don't need the #available logic in the code any more? Thank you!
3
0
3k
Sep ’21
Official reference for "#available" in Swift language?
Hi! In some code and articles online I can see the usages/introductions of using "#available" block to conditionally run code depending on the environment. For example: if #available(iOS 13, *) { // use UICollectionViewCompositionalLayout } else { // show sad face emoji } However, I don't exactly know what kind of programming language feature is "#someName" called in Swift. I also wasn't able to find the official reference of "#available" from swift.org. I can find the reference to "@available" and understand it is an "attribute", and there are many other attributes in Swift with different names. However, what is "#available"? Can anybody tell me whether there is official reference? and what language feature it is classified as? Thank you!
1
0
775
Sep ’21
How to get the UIViewController instance for displaying dialog when the app starts up?
Hi! iOS/MacOS developers, I am trying to integrate a SDK to my iOS app, and I need to call a function provided by the SDK when the app starts running, to display a dialog. My iOS app is developed with SwiftUI. For now, I attempt to add the code to the didFinishLaunchingWithOptions delegate of the AppDelegate.swift file, like the following: import MoPubSDK // ... // Check whether you must show the consent dialog MoPub.sharedInstance().shouldShowConsentDialog; MoPub.sharedInstance().loadConsentDialog(){ a in MoPub.sharedInstance().showConsentDialog( from: myUIViewController, completion: nil)} However, I don't know how I can get the myUIViewController variable. My questions are: how can I get a UIViewController instance when the app starts, such that I can pass it into the SDK function for dialog display? If it is not possible to do it in AppDelegate.swift, can it be done some where else? Thank you!
3
0
2.4k
Aug ’21
What language is the "unbrella" keyword from?
Hi! Developers, I am learning how to use CocoaPods and trying to understanding what it is adding to the project. After "pod install" the randomly chosen "SwiftyJSON" pod to the test XCode project, a "Pods" project is added. After opening the auto-generated workspace by CocoaPods, in the XCode navigation panel, there is a "SwiftyJSON.modulemap" file in "Pods->SwiftyJSON->Support Files". The code in SwiftyJSON.modulemap is like: framework module SwiftyJSON umbrella header "SwiftyJSON-umbrella.h" export * module * {export * } I am wondering, what is the programming of the code in this file? Is it Objective-C? or Swift? or some other kind of language? I tried to search the information using the "umbrella" keyword, but couldn't yet find clear reference. Thank you!
4
0
1.2k
Aug ’21
SwiftUI: memory leaks if update environment object in a view
Hi! I encountered a memory leak issue when trying to use environment object to route the view display of the application. Can you help me to get some idea why the leak happens and how to resolve it? I use the following AppRootView as the contentView in SceneDelegate. struct AppRootView: View {     @EnvironmentObject var appState: AState     var body: some View {         appState.updateIsSignedAgreementUpToDate()         return VStack{             if false {                 MainPageView()             }             else {                 AgreementView()             }         }     } } Following is the class I use for environment variable class AState : ObservableObject {     static let sharedInstance = AState() 		@Published var isSignedAgreementUpToDate : Bool = false     func updateIsSignedAgreementUpToDate() {         self.isSignedAgreementUpToDate = false     } 		private init() { 		} } When I run the code, neither the MainPageView nor the AgreementView will display, and the memory usage is keep increasing. I added a breakpoint to the AppRoot view, and found that it is running again and again. However, from the call stack I cannot find any clue why this happens. If I do the following, the application will start without memory leak: comment out the calling of appState.updateIsSignedAgreementUpToDate() in AppRootView; or comment out the line of self.isSignedAgreementUpToDate = false in AState class; or replace the Stack in AppRootView to simply a MainPageView or a AgreementView. I am testing the app in Simulator with iOS14, with Xcode 12. Thank you!
2
0
2.2k
Oct ’20
How to have a popup alert followed by a navigation push?
Hi! I am trying to implement a button that shows an popup message and then immediately navigate to next view. However, the navigation push does not happen after the alert is displayed. Can you help me to find a solution?Below is how the code I have looks like:struct ContentView: View { @State var showDetail: Bool = false @State private var displayPopupMessage: Bool = false var body: some View { VStack { NavigationLink(destination: DetailView(), isActive: self.$showDetail) {EmptyView()} Button(action: {showDetail = prepossess()}) {Text(“Alert and Navigate”)} } .alert(isPresented: self.$displayPopupMessage){ Alert(title: Text(“Warning”), message: Text(“This is a test”), dismissButton: .default(Text("OK")))} } private func prepossess() -> Bool { self.$displayPopupMessage = true return true } }When I pressed the button, the alert message will show up, but the navigation will not happen, neither before or after dissmissing the alert message. I debugged into the "action" closure of the button, and found the value of the "showDetail" state variable was updated.I attempted to use the legacy UIAlert from UIKit instead of the new SwiftUI machenism, but still got the same result.Can you give me some idea how to have the navigation follow the alert?
5
1
5.3k
Dec ’19
Why ForEach cannot include extra logic?
Hi! I am trying to add some logic in ForEach to compute the views, but XCode does not allow that. Can you tell me why?ForEach(0...10, id: \.self, content: { i in let s : Int = i return Text("abc") }XCode will return error message for the above coce: Cannot convert value of type '(_) -> _' to expected argument type '(_.Element) -> _'However, the code below will work:ForEach(0...10, id: \.self, content: { i in return Text("abc") }I looked at the declaration of ForEach, but couldn't find why it doesn't accept the "let" statement.init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content)I understand that if I put the logic in a separate structure view for each cell, I can get the code work, but just trying to get a better understanding on SwiftUI and posted this question.Thank you!
3
0
1.4k
Dec ’19
How to check conditions before navigating?
Hi! I used NavigationLink to implement navigation. In some links I want to make sure some conditions are satisified when users tap on it. If the conditions are not satisfied, I want to stop the navigation and give an error message. I could do this in UIKit using shouldPerformSegue delegate function, but don't know how to do it in SwiftUI. Can you tell me some idea about how I can do it?More details. When user tap the link, I want to let the app download some data from Internet and parse it, such that it can be passed into the next view. If for any reason the download fails (for example, no network connection), I want the app to display an error message without navigating. I want to do the download right before navigation is because I want to let the app download the newest data, and avoid unnecessary downloads.Thank you!
2
0
2.1k
Dec ’19
SwiftUI equivalent to viewWillTransition event in UIKit?
Hi! In an app implemented using SwiftUI, I want to execute some code when a view changes size. In the previous framework (UIKit), this can be done by using viewWillTransition event in UIViewController, but I cannot find a SwiftUI equivalent now. Do you have an idea how to do that?More detail of the issue I encountered:I am following the ADMOB documentation to include adaptive banner ad in the app, and the ADMOB instruction uses the viewWillTransition eventhttps://developers.google.com/admob/ios/banner/adaptiveI has successfully included a banner app using UIViewRepresentable to wrap the ADMOB object that originally supports UIKit, but just missing the way to respond to layout change of the app (more specifically, rotation).Thank you!
2
0
2.6k
Dec ’19
Xcode local developer documentation is incomplete
Hi! I found that the local developer documentation is in complete, because I was able to find a more complete documentation page in Apple's website.I am using the up-to-date XCode (version 11.3). When coding in SwiftUI mode, I opened the "Developer Documentation" from "Help" menu. In the documentation window I opened the pagge for Button.onTapGesture method. This page-- had no overview description available-- had no "See Also" section.However, I found this link in Apple website presenting the above missing information.https://developer.apple.com/documentation/swiftui/button/3363082-ontapgestureIs there any way I can view the complete documentation from local?Thank you!
4
0
1.2k
Dec ’19
How to embed List in ScrollView using SwiftUI
Hi! I want to allow user to scroll a long list of items iOS app, so I am trying to embbed a List view in ScrollView view. However, the preview result doesn't work. Can you help me to check what I am missing?Below is my experimental code I entered to the file ContentView.swift, started with Single Page App project.struct ContentView: View { var body: some View { ScrollView{ List{ Text("abc") Text("def") } .border(Color.yellow, width: 3) .background(Color.blue) }.padding(10).border(Color.red, width: 3) } }The preview of this code shows the red borders of the ScrollView, but not showing anything for the list, nor the text inside. If I change "List" to "VStack", then everything worked as expected.I don't understand why List doesn't work, and don't know how to fix it. Can you help me to find some clue?Thank you!
6
1
21k
Dec ’19
Can I use an old Mac machine to develop new iOS app?
Hi! I have an old mid-2011 iMac, such that I cannot install the new version of software on it (OS X & XCode). The newest OS X (Mojave) only support iMac 2012 or after, such that I can only use OS High Sierra now, with XCode 10.x. When I created an iOS project with XCode, the displayed "Deployment Target" is only up to 12.1. Does this mean the app I created only work for iOS 12, but not iOS 13?In this situation, if I want to develop iOS 13 app, is it necessary for me to get another Mac machine?Thank you!
2
0
5.3k
Jul ’19