Skip to content

Commit

Permalink
feat: more ios setup
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Jul 2, 2024
1 parent 2b233fb commit c08d51c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ yarn-error.log

# Expo
.expo/*

ausweis-example/.expo
6 changes: 6 additions & 0 deletions ausweis-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
55 changes: 53 additions & 2 deletions plugin/src/withIosAusweisSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ConfigPlugin } from '@expo/config-plugins'

import fs from 'node:fs/promises'
import path from 'node:path'
import { withDangerousMod } from '@expo/config-plugins'
import { withDangerousMod, withEntitlementsPlist, withInfoPlist, withPlugins } from '@expo/config-plugins'
import { type MergeResults, mergeContents } from '@expo/config-plugins/build/utils/generateCode'

// const podSource = `pod 'AusweisApp2', :path => File.join(File.dirname(\`node --print "require.resolve('@animo-id/expo-ausweis-sdk/package.json')"\`), "ios/Specs")`
Expand Down Expand Up @@ -43,8 +43,59 @@ const withIosAusweisApp2Pod: ConfigPlugin = (config) => {
])
}

const NfcReaderSessionFormatsKey = 'com.apple.developer.nfc.readersession.formats'
const NfcReaderSessionIdentifiersKey = 'com.apple.developer.nfc.readersession.iso7816.select-identifiers'

const withIosAusweisEntitlements: ConfigPlugin = (config) => {
const configWithInfoPlist = withInfoPlist(config, (c) => {
if (!c.modResults.NFCReaderUsageDescription) {
c.modResults.NFCReaderUsageDescription = 'NFC is used for authentication using your eID card'
}

const nfcReaderSessionIdentifiers = c.modResults[NfcReaderSessionIdentifiersKey]

if (nfcReaderSessionIdentifiers && !Array.isArray(nfcReaderSessionIdentifiers)) {
throw new Error(`Expect ${NfcReaderSessionIdentifiersKey} to be an array`)
}

if ((nfcReaderSessionIdentifiers as string[])?.includes('TAG')) {
return c
}

if (nfcReaderSessionIdentifiers) {
c.modResults[NfcReaderSessionIdentifiersKey] = Array.from(
new Set([...(nfcReaderSessionIdentifiers as string[]), 'E80704007F00070302'])
)
} else {
c.modResults[NfcReaderSessionIdentifiersKey] = ['E80704007F00070302']
}
return c
})

const configWithEntitlements = withEntitlementsPlist(configWithInfoPlist, (c) => {
const nfcReaderSessionFormats = c.modResults[NfcReaderSessionFormatsKey]

if (nfcReaderSessionFormats && !Array.isArray(nfcReaderSessionFormats)) {
throw new Error(`Expect ${NfcReaderSessionFormatsKey} to be an array`)
}

if ((nfcReaderSessionFormats as string[])?.includes('TAG')) {
return c
}

if (nfcReaderSessionFormats) {
c.modResults[NfcReaderSessionFormatsKey] = Array.from(new Set([...(nfcReaderSessionFormats as string[]), 'TAG']))
} else {
c.modResults[NfcReaderSessionFormatsKey] = ['TAG']
}
return c
})

return configWithEntitlements
}

const withIosAusweisSdk: ConfigPlugin = (config) => {
return withIosAusweisApp2Pod(config)
return withPlugins(config, [withIosAusweisEntitlements, withIosAusweisApp2Pod])
}

export { withIosAusweisSdk }

0 comments on commit c08d51c

Please sign in to comment.