Post

Replies

Boosts

Views

Activity

Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
endecotp: the syntax that surprised be was: [MyAppTransaction checkReceiptWithCompletionHandler:^(NSString * _Nonnull status) { NSLog(@"status: %@", status); }]; I'm not having a problem with it but I never saw it until it was posted here. Also I don't know how Swift types map to Objective-C types. Quinn mentioned that String is equivalent to NSString. This makes sense but it would be useful if all of this was documented somewhere.
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
It would be helpful if I could read the name-Swift.h header to see how to invoke the Swift object methods. The project runs with this invisible header included but it isn't visible in my project hierarchy, Find can't find it, Spotlight can't find it, Open Quickly can't find it and XCode -> Find can't find it. This is extremely unhelpful.
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
I got this to work and this is REALLY WEIRD: If I #import the name-Swift.h header in a .m file the project will build and I can use the MyAppTransaction object in my .m files. BUT XCode doesn't actually create the file in my project directories. Apparently it's cryptic, invisible, implied or something. It would have saved me a huge amount of trouble if the developer documentation described this or if someone mentioned it. Also I never would have guessed that you would have to invoke the method using that syntax. Are a lot of the calls to Swift objects as weird as that? Is there some documentation about this? Update: I spoke too soon. This will work in my test project but not on a major project for a Mac App on the App Store. Something in the build settings?
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
I already have a test project. I also created a test project App->objective-C. With both of these when I add the receipt validation Swift file to the projects XCode asks me if I want to create a bridging header. It creates the name-Bridging-header.h. This is not the bridging head I want. I want the name-Swift.h header. The name-bridging-headers are empty. Shouldn't they at least have this: #ifndef name_Bridging_Header_h #define name_Bridging_Header_h #endif /* name_Bridging_Header_h */ So XCode doesn't create the bridging header. Is there something missing in the build settings or something? Update: things have gone from bad to worse. I removed the Swift files from both projects, build them and when I add the Swift file it adds it to the projects but doesn't ask to create a bridging header. Update 2: If I delete the Swift files, clean and rebuild my test project and add the Swift File, XCode will automatically create the two bridging headers. They will have the #ifndef, #define #endifs in them but no Objective-C prototype in the name-Swift.h header for the Swift Function to verify receipts.
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
The name-Swift.h header was filled in by XCode: #ifndef Chac_Swift_h #define Chac_Swift_h #endif /* Chac_Swift_h */ The Swift object.swift file: import StoreKit @objc class MyAppTransaction: NSObject { @objc class func checkReceipt() async -> String { do { let verificationResult = try await AppTransaction.shared switch verificationResult { case .unverified(_, _): return "NG" case .verified(_): return "OK" } } catch { return "ERR" } } } This will build if my target is at least 10.13 but there's no prototype in the name-Swift.h file. I thought that XCode was supposed to create this? Calling [MyAppTransaction checkReceipt] from a .m file will result in an error - Class method +checkReceipt not found. Theoretically something in the -Swift.h file like: @interface MyAppTransaction : NSObject - (NSString*)checkReceipt; @end Should allow XCode to recognize the Class method, but what?
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
No, endecotp, I can check what it's running on at run-time but that's not the problem. You can't build the project using AppTransaction unless you target at least 13. And there are some conversations about @available on these forums but not in the developer documentation. Also if you target something like 10.15 you will get a whole bunch of compiler warnings about the security functions in your verification code being deprecated. [MyAppTransaction checkReceiptWithCompletionHandler:^(NSString * _Nonnull status) { NSLog(@"status: %@", status); }]; Won't build - unknown object MyAppTransaction. Maybe some guidance about what to put in the bridging header would help?
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
Quinn, your procedure doesn't work: When I create the Swift file, XCode doesn't ask me if I want to create a bridging header. The project won't build without it. Also XCode asks me what I want to subclass. Is NSObject right? The project won't compile without projectname-Swift.h Manually creating a projectname-Swift.h seems to work - it is filled in by XCode. The project won't build without projectname-Bridging-Header.h. Manually creating it and adding it to the project seems to work - XCode fills it in but I get an error: "Did you forget to declare this file as an output of a script phase or custom build rule which produces it?" Huh? Isn't this a header file I can #import into my project? Also the undocumented API @available doesn't look usable because it checks the environment at runtime. What I would need would be conditional compilation, right?
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
Quinn, your code won't compile : let verificationResult = try await AppTransaction.shared reports an error: AppTransaction is only available in macOS 13 or newer. I'm running on 15.0.1 so It looks like I can only use AppTransaction if I target 13 or later. If I do this it is likely that my program will crash when some users launch it. bummer...
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
AppTransaction is available on macOS 13. If you are supporting users on earlier OSes you have to check for this and use the (deprecated?) receipt validation technique. I use this: BOOL runningOnAtleast(int majorVersion, int minorVersion, int patchVersion) { NSOperatingSystemVersion OSVersion; //struct with three variables declared as NSIntegers: OSVersion.majorVersion = majorVersion; OSVersion.minorVersion = minorVersion; OSVersion.patchVersion = patchVersion; return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: OSVersion]; }
Oct ’24
Reply to AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
All I need to do is execute one line of Swift: let verificationResult = try await AppTransaction.shared and look at verification result. According to the less-than-worthless documentation here: https://developer.apple.com/documentation/swift/importing-swift-into-objective-c “You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file.” Generating the header file and including it in my project and .m file doesn't make XCode recognize the types. Theoretically you could call some C version of the above line from your .m file. Carefully following the incomplete documentation I can’t do it so Xcode will recognize the three types, verificationResult (also spelled as VerificationResult, upper case ‘V’ in the documentation), AppTransaction and its method, shared. Including AppTransaction (and verificationResult and shared) in my .m code results in a error: Use of undeclared identifier ‘AppTransaction’ (all three types); XCode doesn't complain about the syntax, it just doesn't recognize the types. Your advice not to try to call StoreKit’s Swift functions directly from objC is good, since it’s not really possible using the developer documentation. The documentation here: https://developer.apple.com/documentation/swift/migrating-your-objective-c-code-to-swift/ Tells me how to sub-class an Objective-C class in Swift to use it in an Objective-C project, but not to do what you describe “Write a short Swift function that calls StoreKit, and call that from objC”. Maybe you know about some documentation describing how to do this?
Oct ’24