-
I am trying to use the ExternalLinkAccount API from Apple and I am a little bit unsure, if I call the API in the Nativescript Javascript runtime correctly. The prerequisites from Apple for using this API should all be fulfilled (the entitlement was added, the SKExternalLinkAccount key is defined and the app is running on iOS 16) If I read the Nativescript documentation correctly, I just can use the API directly, i.e. function openExternalAccount() {
if (!isIOS) {
return
}
if (PKPaymentAuthorizationController.canMakePayments() && ExternalLinkAccount.canOpen) {
ExternalLinkAccount.open()
}
} If I do that the app compiles and starts, but I get an error when the API is called on a real device running iOS 16:
I also see that this API is not mentioned in any Nativescript repository and that there are no type definitions. Does this API has to be defined for the Nativescript Javascript runtime before I can start using it? This API was just introduced in iOS 16, so there might be something missing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Seems like A workaround for now would be to manually expose it to ObjC from a Swift file in import Foundation
import StoreKit
@objc
@objcMembers
class StoreKitCompat: NSObject {
@available(iOS 16.0.0, *)
static func ExternalLinkAccountCanOpen() async -> Bool {
return await ExternalLinkAccount.canOpen
}
@available(iOS 16.0.0, *)
static func ExternalLinkAccountOpen() async {
do {
return try await ExternalLinkAccount.open()
} catch {
}
}
} This would then be automatically picked up & usable with the following interface (genrated with declare class StoreKitCompat extends NSObject {
static ExternalLinkAccountCanOpenWithCompletionHandler(completionHandler: (p1: boolean) => void): void;
static ExternalLinkAccountOpenWithCompletionHandler(completionHandler: () => void): void;
static alloc(): StoreKitCompat; // inherited from NSObject
static new(): StoreKitCompat; // inherited from NSObject
} So in your code you would do something like: StoreKitCompat.ExternalLinkAccountCanOpenWithCompletionHandler((canOpen) => {
console.log('canOpen', canOpen)
if(canOpen) {
StoreKitCompat.ExternalLinkAccountOpenWithCompletionHandler(() => {
console.log('done.')
})
}
}) |
Beta Was this translation helpful? Give feedback.
Seems like
ExternalLinkAccount
is currently only exposed to Swift and not ObjC. NativeScript currently generates metadata for symbols discoverable through ObjC, so in this case it can't find it.A workaround for now would be to manually expose it to ObjC from a Swift file in
App_Resources/iOS/src/StoreKitCompat.swift
(or whatever name makes sense):