In our app, we are retrieving the SIM card country code.
CTTelephonyNetworkInfo().serviceSubscriberCellularProviders
But 'serviceSubscriberCellularProviders' was deprecated in iOS 16.0 with no replacement.
So in iOS 17, is there any other way to get a SIM card-based country code?
Dive into the world of programming languages used for app development.
Post
Replies
Boosts
Views
Activity
Hi.
Is it possible to get all Safari/Chrome open tabs with AppleScript? Is it also possible to check if tab audio is enable/play video/music?
macOS
Thank you!
I tested my code to detect fake locations in two ways:
Receiving location updates from func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]). This code returns location?.sourceInformation?.isSimulatedBySoftware as true (which is correct for my scenario)
Getting CLLocationManager().location directly. This code returns location?.sourceInformation?.isSimulatedBySoftware as false (which is incorrect)
Why CLLocationManager().location returns the correct location infos but not return correct isSimulatedBySoftware info?
This error is generated at the first case statement in my example code.
Type 'Binding' has no member 'atype1'
If I change the order of the cases in the switch statement, it is always the first one which gives the error.
In my code, if you delete the value of that first switch line, and type it in again, as soon as you have entered 'case .' the drop down menu will offer suggestions and you can see the atype1 & atype2 near the top of the list.
What am I doing wrong?
import SwiftUI
enum AType: CaseIterable {
case atype1
case atype2
case unknown // default
}
struct Peripheral: Identifiable {
let id: Int
let name: String
var type: AType = .unknown
}
struct ContentView: View {
@State private var peri = Peripheral(id: 1, name: "A")
var body: some View {
switch $peri.type {
case .atype1:
Text("Hello, $peri.name!")
case .atype2:
Text("Goodbye, $peri.name!")
case .unknown:
Text("Oh no!")
}
.padding()
}
}
#Preview() {
ContentView()
}
Hey guys,
I saw that both the Mona (Mastodon client) and the Telegram app offer translations on post through the click of a button. They both offer to select "Apple Translate" as a translation service. Both apps are available through the App Store.
I'm wondering how they're doing it :) I couldn't find an official, public API to tap into the LTUITranslationViewController they're presenting. On the other hand they've both run through the app review process and using private APIs should have thrown a red flag.
I thought that they may have setup a custom shortcut through which they trigger the Apple Translate app, but there are no shortcuts by these apps in the Shortcuts app.
This is what shows up when you hit the "Translate" button on a post:
I was able to run Scanning objects using Object Capture, and get the bounding box after tapping "Continue" button.
Does the code output BoundingBox properties as well? For example, the vertex of all corners of the bounding box?
In the Apple document, If success, the session state will eventually transition to .detecting and switch to the bounding box selection mode UI, what UI? Anyone has link so I can look into?
Thanks!
I use a .fileExporter-sheet to export some fles. In that view the save and the back button are invisible due they are rendered in white color of white background.
That begins with iOS 15.0 and still remains with iOS 17.0.
Is there any way to modify the fileexporter-sheet ui?
Thanks in forward! Cheers!
Im creating a simple chatbox using an api caller library I created and imported but it looks like Xcode is not recognizing the modules as I get multiple "no member" errors for the 'ChatClient' module.
`import SwiftUI
import openaiLibrary
final class ViewModel: ObservableObject {
private var openAI: openaiLibrary.ChatClient
init(apiKey: String) {
let config = openaiLibrary.ChatClient.OpenAIEndpointProvider.makeDefaultKey(api_key: apiKey, endpointProvider: openaiLibrary.ChatClient.OpenAIEndpointProvider())
self.openAI = openaiLibrary.ChatClient(apiKey: apiKey, openaiEndpoint: config.baseURL)
}
public func sendAIRequest(with search: String, completion: @escaping(Result<String,Error>) -> Void) {
openAI?.sendCompletion(with: search) { result in
switch result {
case .success(let response):
if let text = response.choices.first?.text {
completion(.success(text))
} else {
completion(.failure(NSError(domain: "error", code: 1, userInfo: [NSLocalizedDescriptionKey: "No response found"])))
}
case .failure(let error):
completion(.failure(error))
}
}
}
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
}
}
#Preview {
ContentView()
}
}
`
I can also provide my source code for my api caller that my openaiLibrary package dependency uses to make sure everything is defined correctly so that Xcode recognizes everything, due to character constraints I wasn't able to fit it in this post.
Just found something weird with the String(localized:) method.
Let's say that I have a "%lld apples" sentence inside a string catalog.
If I call
String(localized:"\(1000) apples")
when on the device settings the number format is "1'234'567.89" and the device language is English, then the following string is returned:
1\'000 apples
Any idea why the ' character has a backslash?
It's a bug or I miss something?
Thank you
I used the command:
utils/build-script --swift-darwin-supported-archs "$(uname -m)" --xcode --clean
and encountered the following error:
CMake Error at cmake/modules/SwiftUtils.cmake:24 (message):
Error! Variable THIN_INPUT_TARGETS is false, empty or not set.
Call Stack (most recent call first):
stdlib/cmake/modules/AddSwiftStdlib.cmake:3068 (precondition)
stdlib/public/libexec/swift-backtrace/CMakeLists.txt:39 (add_swift_target_executable)
Please let me know the solution to this error.
Thank you.
Have a great day as well. 👍
I was going through this apple documention and it states, "By default, the generated header contains interfaces for Swift declarations marked with the public or open modifier", however, In my Xcode project, the public methods are not visible in the objective C code, and only the methods that are marked with @objc are visible. Is there some problem in my code or Is this a bug?
// The builtin encoding does not support GBK/GB2312
String(data: data, encoding: .GBK)
How do I convert data which is encoded in GBK/GB2312 (or anything else) to a string instance?
I am a newbie in app development. I want to use Swift to make an English dictionary. If there is any master can provide me word database APIS? Thank you. Wish you the best of luck!
I'd like to talk to someone at Apple that could help with a new programming language(s). There's several key features that could help Apple OS's be the best place for developers. Some of these features are:
-Fast and small multiple inheritance (this one is huge, the entire reason people still use C++)
-XML/JSON integration
-Simplified databases
-All smart pointers so no garbage collection required
-Much more
Basically there's multiple languages that compile into a object-oriented language. It's similar to .net in that way but the OO language is a little higher level than .net. Making a new language that works with OO is as simple as copying C#+ or Swift+ and modifying it.
I'm not sure where to go with this so any help would be greatly appreciated!
Hello,
I am trying to use the SwiftUI fileImporter to get the URL of a direcotry and access it for the files in it.
If I follow the document( Access the directory’s content ) and use url.startAccessingSecurityScopedResource for each file, it always returns false. but this seems to be different from the documentation. If the current behavior is correct, will the documentation be updated in the future?
Related: Access all files in UIDocumentPick… | Apple Developer Forums
I asked this question because I am concerned that if I remove the standardAccessingSecurityScopedResource to match the current situation, the standardAccessingSecurityScopedResource may become necessary due to future iOS updates.
Also, is there any way to know if the status of the AccessingSecurityScopedResource?
It would be helpful if we could callstartAcesingSecurityScopedResource only when needed.
Thanks
Here is a sample code
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var isShowingImportFolder = false
@State private var isShowingImportFile = false
var body: some View {
VStack(spacing: 48) {
Button("Read Folder") {
isShowingImportFolder = true
}
.fileImporter(isPresented: $isShowingImportFolder, allowedContentTypes: [.folder]) { result in
switch result {
case .success(let url):
processDirectory(url)
case .failure(let error):
print("failed. error: \(error)")
}
}
Button("Read File") {
isShowingImportFile = true
}
.fileImporter(isPresented: $isShowingImportFile, allowedContentTypes: [.data]) { result in
switch result {
case .success(let url):
readFile(url)
case .failure(let error):
print("failed. error: \(error)")
}
}
}
}
private func processDirectory(_ directory: URL) {
guard directory.startAccessingSecurityScopedResource() else {
fatalError("failed. directory.startAccessingSecurityScopedResource")
}
defer { directory.stopAccessingSecurityScopedResource() }
var error: NSError?
NSFileCoordinator().coordinate(readingItemAt: directory, error: &error) { url in
let urls = try! FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: [.nameKey, .isDirectoryKey])
urls.lazy
.filter { !$0.hasDirectoryPath }
.forEach { readFile($0) }
}
}
private func readFile(_ url: URL) {
guard url.startAccessingSecurityScopedResource() else {
print("failed access. \(url.path)")
return
}
defer { url.stopAccessingSecurityScopedResource() }
let data = try! Data(contentsOf: url)
print("file.path: \(url.path()), size: \(data.count)")
// read file...
}
}
Hi,
Is there a way where programmatically obtain device UDID on Xcode 15 or Swift 5?
Aware there are two different sets, UDID & UUID. What I'm looking for is UDID. As per research seems impossible.
Help on this would be appreciated.
I cannot validate because keep getting error: Asset validation failed
Missing Info.plist value. A value for the Info.plist key 'CFBundleIconName' is missing in the bundle 'com.***.YYY'. Apps built with iOS 11 or later SDK must supply app icons in an asset catalog and must also provide a value for this Info.plist key. For more information see http://help.apple.com/xcode/mac/current/#/dev10510b1f7. (ID: 47751d4c-80e7-42e0-8b8d-c9f6943aadac)
In my Mac application, I am trying to get the active microphone mode using the AVCaptureDevice's activeMicrophoneMode, it returns the correct value in m1 and m2. But I always get the default standard value when I check with appstore build of my app in Intel system. It works proper with webstore build in Intel. But I am not sure why intel has some issue with the appstore build. I also tried with AVCaptureDevice's preferredMicrophoneMode. Still the same.
I implemented drag drop in my iOS app and sometimes, the dragged item gets stuck on the screen. The only way to remove it is by restarting the phone.
Has anyone else faced this issue? And how did you resolve it?
I'm trying to run UITests just once. However, Xcode by default seems to run every permutation of light/dark color theme and device orientation and localizations. This means all UITests run 8 times (with 1 additional localization besides English). With tests that can take a couple minutes, the time to run all these adds up.
Nothing in my UITest depends on the color theme, so I'd like to turn those permutations off always. The orientation and localization variations I might want sometimes but would generally also like to turn off.
Questions:
Can I disable any/all of these permutations?
How can I get the locale string for the current run? I've tried using Locale(identifier: Locale.preferredLanguages.first!) but this just gets the device language, not the language being used on that run of the UI Test.
Minimal reproducible example:
Make a new SwiftUI app project in Xcode 15.
Add a UI Testing Bundle target
Add a localization in the general app settings, then add a string catalog called Localizable and at least one string's translation in that string catalog.
Run a UITest
Observe that it runs 8 times.
Thanks for the help!