Hello,
I'm currently developing a SwiftUI app for macOS that includes both free and premium features. One of the features is the maximum amount of items that can be stored in the app: the free version allows users to store up to 10 items, whereas premium users can store up to 1000.
The issue I'm facing is with securing the premium feature. I'm using UserDefaults to store the value of the feature, with a key named maxStorageSize. The user can configure this using a dropdown (there are also other options between 10 and 1000). For non-premium users, this dropdown is disabled and set to a default of 10. For premium users, the dropdown is enabled and thus the user can change the setting to a higher value.
However, I've realised that this limitation can be bypassed by using the defaults CLI tool to change the value of maxStorageSize underneath the application's knowledge, effectively circumventing the premium requirement.
My current workaround is:
check the user defaults on launch and if the user is non-premium and any of the premium features have been changed: reset them.
continuously monitor for updates on the defaults and if the user is non-premium and a premium feature value has been changed: reset it.
This seems to work but feels a little hacky. I'm wondering what mechanisms you've come up with to solve this.
Dive into the world of programming languages used for app development.
Post
Replies
Boosts
Views
Activity
I want to read metadata of image files such as copyright, author etc.
I did a web search and the closest thing is CGImageSourceCopyPropertiesAtIndex:
- (void)tableViewSelectionDidChange:(NSNotification *)notif {
NSDictionary* metadata = [[NSDictionary alloc] init];
//get selected item
NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]];
//set path to file selected
NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData];
//declare a file manager
NSFileManager* fileManager = [[NSFileManager alloc] init];
//check to see if the file exists
if ([fileManager fileExistsAtPath:filePath] == YES) {
//escape all the garbage in the string
NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8);
//convert path to NSURL
NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString];
NSError* error;
NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]);
//declare a cg source reference
CGImageSourceRef sourceRef;
//set the cg source references to the image by passign its url path
sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL);
//set a dictionary with the image metadata from the source reference
metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
NSLog(@"%@", metadata);
[filePathURL release];
} else {
[self showAlert:@"I cannot find this file."];
}
[fileManager release];
}
Is there any better or easy approach than this?
Hello Apple Developer Community,
I represent a team working on an iOS application that interacts with a Bluetooth Low Energy (BLE) module in vehicles. We're exploring advanced functionalities and have a couple of queries:
Automatic PIN Handling: Is there a method for our app to programmatically input a PIN for Bluetooth pairing, bypassing the usual popup prompt? We aim to streamline the user experience by eliminating manual PIN entry.
Programmatic Bond Management: Can our app directly "forget" a paired Bluetooth device without requiring the user to manually do so in the iOS settings? This feature would significantly enhance our app's usability.
MFi Certification Benefits: Would obtaining MFi certification enable any of the above functionalities, or provide us with additional APIs or capabilities to manage Bluetooth connections more effectively?
We appreciate any guidance or insights you can provide on these matters. Understanding these capabilities is crucial for the development of our application.
Thank you in advance for your assistance.
Best regards,
As I was watching WWDC19 Session: "LLDB: beyond "po" " I got confused about "p" command. In the session there was a following example to show how "p" command works:
// Struct for demonstration purposes
struct Trip {
var name: String
var destinations: [String]
let cruise = Trip (
name: "Mediterranean Cruise"
destinations: ["Sorrento", "Capri", "Taormina"])
Using "p" to get info about cruise instance:
(lldb) p cruise
(Travel.Trip) $R0 = {
name = "Mediterranean Cruise"
destinations = 3 values {
[0] = "Sorrento"
[1] = "Capri"
[2] = "Taormina"
}
}
I was following along and wrote the same code. But the output from LLDB turned out to be different:
(lldb) p cruise
(LLDB_Apple_Session_FollowAlong.Trip) {
name = "Mediterranean Cruise"
destinations = 3 values {
[0] = "Sorrento"
[1] = "Capri"
[2] = "Taormina"
}
}
As you can see LLDB didn't create a global variable R0 which I could later use in my debugging session and that seemed strange to me.
Then the presenter said the following:
"p" is just an alias for the "expression" command.
So, I tried to use the "expr" command to see if they're actually the same and they turned out to be different commands. The output I got from "expr" was the one I expected from "p":
(lldb) expr cruise
(LLDB_Apple_Session_FollowAlong.Trip) $R0 = {
name = "Mediterranean Cruise"
destinations = 3 values {
[0] = "Sorrento"
[1] = "Capri"
[2] = "Taormina"
}
}
Finally, my question is:
Am I wrong somewhere or did something change in LLDB regarding "p" and "expr" commands and if so, where could I get more information about the changes?
can someone please help me, I am new to using Xcode and SwiftUI, I recently updated to Sonoma and now am having issues building and running projects.
i am creating this for a class assignment due in a few days any help is appreciated.
currently I am having this error upon simply creating a new file:
"
Showing Recent Errors Only
Build target ImageApp of project ImageApp with configuration Debug
CodeSign /Users/carina/Library/Developer/Xcode/DerivedData/ImageApp-braozmttxaqevhglgrebdherlmlh/Build/Intermediates.noindex/Previews/ImageApp/Products/Debug/ImageApp.app (in target 'ImageApp' from project 'ImageApp')
cd /Users/carina/Desktop/AME\ 430/ImageApp
Signing Identity: "Apple Development: [my email] (B75Q73AMVQ)"
/usr/bin/codesign --force --sign 9AFE419D4A362429289B899DECCFB65E5F68E135 -o runtime --entitlements /Users/carina/Library/Developer/Xcode/DerivedData/ImageApp-braozmttxaqevhglgrebdherlmlh/Build/Intermediates.noindex/Previews/ImageApp/Intermediates.noindex/ImageApp.build/Debug/ImageApp.build/ImageApp.app.xcent --timestamp\=none --generate-entitlement-der /Users/carina/Library/Developer/Xcode/DerivedData/ImageApp-braozmttxaqevhglgrebdherlmlh/Build/Intermediates.noindex/Previews/ImageApp/Products/Debug/ImageApp.app
/Users/carina/Library/Developer/Xcode/DerivedData/ImageApp-braozmttxaqevhglgrebdherlmlh/Build/Intermediates.noindex/Previews/ImageApp/Products/Debug/ImageApp.app: replacing existing signature
/Users/carina/Library/Developer/Xcode/DerivedData/ImageApp-braozmttxaqevhglgrebdherlmlh/Build/Intermediates.noindex/Previews/ImageApp/Products/Debug/ImageApp.app: resource fork, Finder information, or similar detritus not allowed
Command CodeSign failed with a nonzero exit code
Command CodeSign failed with a nonzero exit code
"
I've pulled the project from Git. Someone else was working on it and it works perfectly fine for them, they can edit all the files. On mine I can only edit what I have added, the files which were already there I can edit, but their changes and additions do not show on the xcode directory on the left side. If i go to finder and click on the project folder there I can see their changes on there..
I tried clicking the lock icon on the preview screen and it says this:
“file.swift” is currently locked because it is a remote resource.
and when clicking Unlock
The file is a remote resource. Try making a local copy.
Literally have no idea what to do now. I tried copying their files and making new files and folders like how they made on their branch but it says its already existing even though it is not showing on my swift directory!
If you need any other information I am happy to provide it for you!
I have gone through (many times) the videos and documentation around adding privacy manifest support to applications and SDKs etc - specifically via the expected PrivacyInfo.xcprivacy file.
I am across adding it to the application, and to libraries that produce an xcframework (and signing those etc), however, I also have a series of Swift Package libraries available on GitHub which afaict will also require the privacy info file to declare the libraries privacy related intentions.
So my questions are:
Where should I add this file within the package setup?
Should there be a privacy info file per importable target?
Is it expected that the generated privacy report of an application will show info about the library?
I have tried within the sources area, and in the root/manifest section, but when I generate a privacy report on the archived application that utilities this library, I can't see any indication that the info is included in the report.
This is the generated privacy report from Xcode organiser:
My libraries do not actually track or access anything in the required API's list, however I also added some user tracking and linking etc to the privacy info file as a test, and it does not indicate that these are happening in the generated privacy report on the application.
Quick example/clarification:
I have tried putting the file here:
MyPackage
- Package.swift
> Sources
> TargetName
- PrivacyInfo.xcprivacy
and here
MyPackage
- Package.swift
- PrivacyInfo.xcprivacy
> Sources
> TargetName
If there are docs that I have missed running through this, please link me 😅- I have searched for some clear answers through docs and forum questions but I can't seem to get clarification.
Hi, I m tried get data json with mvvm structure but get parsing error. How do can I get data?
My Model
struct eczaModel: Codable {
let data: [Datum]
}
// MARK: - Datum
struct Datum: Codable {
let eczaneAdi, adresi, semt, yolTarifi: String
let telefon, telefon2, sehir, ilce: String
let latitude, longitude: Double
enum CodingKeys: String, CodingKey {
case eczaneAdi = "EczaneAdi"
case adresi = "Adresi"
case semt = "Semt"
case yolTarifi = "YolTarifi"
case telefon = "Telefon"
case telefon2 = "Telefon2"
case sehir = "Sehir"
case ilce, latitude, longitude
}
}
iOS 16 apparently included the ability for the Lock Screen wallpaper to shuffle through a dedicated folder.
Is there a way to update the wallpaper from an app in the background on any version of iOS before iOS 16 ?
Unknown dynamically requested build input cannot be found, on Compiling GeneratedAssetSymbols.swift, Unexpected input file: /Users/myuser/Documents/ios-projects/test-app/platforms/ios/MyApp.build/Debug-iphonesimulator, on xcode 15.0.1
Does Swift support this? Til now my understanding is that reflection only works with public members. Is it possible to get private/static members of a type?
I have an image. The table has many columns and associated rows with it. Is it possible to recognize a particular column's key and values from the table?
Hi Team,
As our application has been successfully distributed to more than 10 clients, we've encountered varying preferences regarding module updates in the latest release. Some clients have expressed the desire to abstain from certain module updates, while others have specifically requested them.
How we can handle above use case in swift code? What is your suggestion ?
Thanks,
Pradip Walghude
I declare a structure type in swift, name as CmdStruct
struct CmdStruct {
var cmd:[UInt8]
init() {
cmd = [UInt8](repeating: 0, count:16)
}
}
In the case that the connection has been obtained.
In sendCmd function, declare a variable which name as input which type of CmdStruct.
After set data to input, call a DriverKit function IOConnectCallStructMethod.
Here xcode shows a warning tip for the parameter 'input' for call IOConnectCallStructMethod:
<Forming 'UnsafeRawPointer' to a variable of type 'CmdStruct'; this is likely incorrect because 'CmdStruct' may contain an object reference.>
func sendCmd() {
var ret:kern_return_t = kIOReturnSuccess
var input = cmdStruct()
var output:[UInt8] = [UInt8](repeating:0, count: 16)
var inputSize = MemoryLayout<CmdStruct>.size // print value 8
var outputSize = output.count // print value 16
input.cmd[0] = 0x12
input.cmd[1] = 0x34
ret = IOConnectCallStructMethod(Connection, selector, &input, inputSize, &output, &outputSize)
}
In C file, driverkit function ExternalMethod will receive the parameter from swift side.
And check the value of input->cmd[0] and input->cmd[1] in console. However, the values are not the expected 0x12 and 0x34.
struct CmdStruct
{
uint8_t cmd[16];
};
kern_return_t myTest::ExternalMethod(uint64_t selector, IOUserClientMethodArguments* arguments, const IOuserClientMethodDispatch* dispatch, OSObject* target, void* reference)
{
int i = 0;
CmdStruct* input = nullptr;
if (arguments == nullptr) {
ret = KIOReturnBadArgument;
}
if (arguments->structureInput != nullptr) {
input = (CmdStruct*)arguments->structureInput->getBytestNoCopy();
}
/*
Here to print input->cmd[0] and input->cmd[1] data to console.
*/
}
I expect that the correct value of input will be show on the driverkit side. I'm not sure which part is wrong. Here, I list some factors that may lead to incorrect value.
How to fix the warning tip for parameter 'input' when call IOConnectCallStructMethod in swift.
I get the inputSize value 8 by using MemoryLayout.size. But this structure contains a 16 bytes array. How to get the correct struct size in swift
In C file side, using (CmdStruct*)arguments->structureInput->getBytestNoCopy() to transform data to C struct is correct?
When calling DispatchQueue.main.async or DispatchQueue.main.sync with a call to self without capturing self, I get a compiler error:
Call to method 'asd' in closure requires explicit use of 'self' to make capture semantics explicit
Since I usually use DispatchQueue.main.async, I'm now used to solving this error by capturing self like this:
DispatchQueue.main.async { [self] in
asd()
}
But this unfortunately doesn't seem to work with DispatchQueue.main.sync:
DispatchQueue.main.async { [self] in
asd()
}
This gives the compiler warning:
Call to method 'asd' in closure requires explicit use of 'self' to make capture semantics explicit; this is an error in Swift 6
This warning only appears for DispatchQueue.main.sync and not for DispatchQueue.main.async. Why? How can I avoid having to prefix every method call with self. in this case?
I created one application using Websocket when TLS version was 1.2 connection establishment working fine but when server team update TLS1.2 to TLS1.3 due to security enhancement in my project i am getting SSL Handshake fails with code 9836. and NSOSStatusErrorDomain with code 9836.
here is my info.plist
NSAppTransportSecurity NSAllowsArbitraryLoads NSExceptionDomains myserver.com NSIncludesSubdomains NSExceptionMinimumTLSVersion TLSv1.3
So my query here is that even if we specify TLSv1.3 for myserver.com as: NSExceptionMinimumTLSVersion TLSv1.3
we want to restrict only to TLS1.3, even if my request fails, how to achieve this?
I am encountering a dyld error (dyld[8942]: Library not loaded) when attempting to embed PaymentSampleFramework within POSSampleFramework, and only linking POSSampleFramework in the main application. The error is as follows:
Referenced from: <99DE58BE-5611-3397-BED2-6D7DDCE5A878> /private/var/containers/Bundle/Application/B4CB8F71-F8A7-4A21-8C1B-170612C3C628/ParentApp.app/ParentApp
Reason: tried: '/usr/lib/swift/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file), '/private/var/containers/Bundle/Application/B4CB8F71-F8A7-4A21-8C1B-170612C3C628/ParentApp.app/Frameworks/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file), '/usr/lib/swift/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file), '/private/var/containers/Bundle/Application/B4CB8F71-F8A7-4A21-8C1B-170612C3C628/ParentApp.app/Frameworks/PaymentSampleFramework.framework/PaymentSampleFramework' (no such file)
The error occurs only when PaymentSampleFramework is not directly added to the application. I want to have only POSSampleFrameWork on the app side, with PaymentSampleFramework included within it.
I have shared the GitHub link to my workspace for reference: https://github.com/sarathdev/MyWorkSpace (Added PaymentSampleFramework inside application to avoid crash)
I'm seeking advice on whether it's possible to embed only POSSampleFrameWork without adding all internal dependencies. Any suggestions or solutions to resolve this issue would be greatly appreciated.
why Apple discourages creating an umbrella framework, is the umbrella setup is the only solution!
hi, I am using the openpty function in my code to run an interactive command, for example, "hdiutil convert -format UDRO /tmp/myFileName.sparsebundle -o ./test". The file myFileName.sparsebundle is an encrypted disk with a password. When running this command, it triggers the security server and a password input dialog box pops up. I don't want this dialog box to appear, and I want to provide the password through the fd_master returned by openpty. How can I achieve this?
I am fetching an image from the photo library and fetch the GPS Location data, but it's not working.
This needs to work on iOS 17 as well, so I used PHPicker. kCGImagePropertyGPSDictionary is always returning nil.
The code I tried:
import CoreLocation
import MobileCoreServices
import PhotosUI
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var selectedImageView:UIImageView!
@IBAction func selectTheImage() {
self.pickImageFromLibrary_PH()
}
func pickImageFromLibrary_PH() {
var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
configuration.filter = .images
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
present(picker, animated: true, completion: nil)
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
if let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) {
itemProvider.loadObject(ofClass: UIImage.self) { (image, error) in
if let image = image as? UIImage {
self.fetchLocation(for: image)
}
}
}
picker.dismiss(animated: true, completion: nil)
}
func fetchLocation(for image: UIImage) {
let locationManager = CLLocationManager()
guard let imageData = image.jpegData(compressionQuality: 1.0) else {
print("Unable to fetch image data.")
return
}
guard let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
print("Unable to create image source.")
return
}
guard let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [String: Any] else {
print("Unable to fetch image properties.")
return
}
print(properties)
if let gpsInfo = properties[kCGImagePropertyGPSDictionary as String] as? [String: Any],
let latitude = gpsInfo[kCGImagePropertyGPSLatitude as String] as? CLLocationDegrees,
let longitude = gpsInfo[kCGImagePropertyGPSLongitude as String] as? CLLocationDegrees {
let location = CLLocation(latitude: latitude, longitude: longitude)
print("Image was taken at \(location.coordinate.latitude), \(location.coordinate.longitude)")
} else {
print("PHPicker- Location information not found in the image.")
}
}
}
Properties available in that image:
Exif/Meta-Data is available, I expect GPS location data
ColorSpace = 65535;
PixelXDimension = 4032;
PixelYDimension = 3024;
}, "DPIWidth": 72, "Depth": 8, "PixelHeight": 3024, "ColorModel": RGB, "DPIHeight": 72, "{TIFF}": {
Orientation = 1;
ResolutionUnit = 2;
XResolution = 72;
YResolution = 72;
}, "PixelWidth": 4032, "Orientation": 1, "{JFIF}": {
DensityUnit = 0;
JFIFVersion = (
1,
0,
1
);
XDensity = 72;
YDensity = 72;
}]
Note: I'm trying in Xcode 15 and iOS 17.
In photos app location data is available, but in code, it's returning nil.
Since Xcode was updated to 15.0.1, UIicker and UIDatePiPcker both are crashing in the app everywhere even with the default picker. They are also crashing in the third party like Stripe and all, error is related to selectrow() method of picker view where it can not find the tableviewcell.