Code Monkey home page Code Monkey logo

react-native-passkit-wallet's Introduction

react-native-passkit-wallet

React Native module to handle PassKit pass.

Installation

1. Install library from npm

npm install --save react-native-passkit-wallet

2. Link native code

You can link native code in the way you prefer:

CocoaPods

Add line to your project target section in your Podfile:

target 'YourProjectTarget' do

+   pod 'react-native-passkit-wallet', path: '../node_modules/react-native-passkit-wallet'

end

If you received error jest-haste-map: Haste module naming collision: Duplicate module name: react-native, add lines below to your Podfile and reinstall pods.

target 'YourProjectTarget' do

+   rn_path = '../node_modules/react-native'
+   pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
+   pod 'React', path: rn_path

  pod 'react-native-passkit-wallet', path: '../node_modules/react-native-passkit-wallet'

end

+ post_install do |installer|
+   installer.pods_project.targets.each do |target|
+     if target.name == "React"
+       target.remove_from_project
+     end
+   end
+ end

react-native link

Run command below:

react-native link react-native-passkit-wallet

3. Android configuration

  1. Add following lines to AndroidManifest.xml

    <manifest
      ...
    + xmlns:tools="http://schemas.android.com/tools"
    >
      <application ...>
        ...
    +   <provider
    +     android:name="androidx.core.content.FileProvider"
    +     android:authorities="com.yourcompany.fileprovider"
    +     android:grantUriPermissions="true"
    +     android:exported="false"
    +     tools:replace="android:authorities">
    +     <meta-data
    +       android:name="android.support.FILE_PROVIDER_PATHS"
    +       android:resource="@xml/passkit_file_paths"
    +       tools:replace="android:resource" />
    +   </provider>
      </application>
    </manifest>
  2. Create passkit_file_paths.xml

    Create passkit_file_paths.xml file in your project's android/app/src/main/res/xml directory. pkpass file will be created in your app's cache directory.

    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <cache-path name="passkit" path="/"/>
    </paths>

Usage

import PassKit, { AddPassButton } from 'react-native-passkit-wallet'

Check whether the device supports adding passes

PassKit.canAddPasses()
  .then((result) => {
    console.log(result)
  })

For Android, true will be returned if apps that can open pkpass files are installed.

Prompt the user to add the pass to the pass library

PassKit.addPass(base64EncodedPass)

For Android, file provider has to be specified for the second argument. And a dialogue box will appear to choose an app to open the pass.

PassKit.addPass(base64EncodedPass, 'com.yourcompany.fileprovider')

Check whether the user’s pass library contains the specified pass (iOS only)

PassKit.containsPass(base64EncodedPass)

Display a button that enables users to add passes to Wallet (iOS only)

class App extends Component<{}> {
  render() {
    return (
      <AddPassButton
        style={styles.addPassButton}
        addPassButtonStyle={PassKit.AddPassButtonStyle.black}
        onPress={() => { console.log('onPress') }}
      />
    )
  }
}

Handle events (iOS only)

class App extends Component<{}> {
  // To keep the context of 'this'
  onAddPassesViewControllerDidFinish = this.onAddPassesViewControllerDidFinish.bind(this)

  componentDidMount() {
    // Add event listener
    PassKit.addEventListener('addPassesViewControllerDidFinish', this.onAddPassesViewControllerDidFinish)
  }

  componentWillUnmount() {
    // Remove event listener
    PassKit.removeEventListener('addPassesViewControllerDidFinish', this.onAddPassesViewControllerDidFinish)
  }

  onAddPassesViewControllerDidFinish() {
    // Add-passes view controller has been dismissed
    console.log('onAddPassesViewControllerDidFinish')
  }
}

Constants (iOS only)

  • PassKit.AddPassButtonStyle - The appearance of the add-pass button
    • black - A black button with white lettering
    • blackOutline - A black button with a light outline
  • PassKit.AddPassButtonWidth - Default add-pass button width
  • PassKit.AddPassButtonHeight - Default add-pass button height

react-native-passkit-wallet's People

Contributors

ajcrites avatar cheloveq avatar lucasmarshall avatar miyabi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-passkit-wallet's Issues

Missing wallet icon from AddPassButton

The exported AddPassButton doesn't render the Apple Wallet Icon

Expected:
alt text
https://developer.apple.com/wallet/

Actual:
Screenshot 2020-06-22 at 09 46 44

Implementation:

<AddPassButton
  // eslint-disable-next-line react-native/no-inline-styles
  style={{ height: 57, borderWidth: 1 }}
  addPassButtonStyle={PassKit.AddPassButtonStyle.blackOutline}
  onPress={() => {
    console.log('onPress');
  }}
/>

_reactNativePasskitWallet2.default.canAddPasses is not a function

Hi, We are attempting to use passkit-wallet on android and we are getting the following error when the following code is run on android

Original code:

  componentDidMount() {
    navigatorStyle = {
      navBarHidden: this.props.vip
    };

    PassKit.canAddPasses().then(result => {
      consloe.log("canAddPasses result: ", result);
      if (!result) {
        alert("Sorry, your device does not support adding passes.");
        _goHome();
      }
    }).catch(error => {
      console.log("canAddPass error: ", error);
    });

    // Add event listener
    PassKit.addEventListener(
      "addPassesViewControllerDidFinish",
      this.onAddPassesViewControllerDidFinish
    );
  }

Error showing up in adb logcat and also in the ReactNative redscreen:

05-17 12:30:13.796  5343 10283 I bugsnag-react-native: Sending exception: TypeError - TypeError: _reactNativePasskitWallet2.default.canAddPasses is not a function
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:
05-17 12:30:13.796  5343 10283 I bugsnag-react-native: This error is located at:
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in PassScreen (created by Connect(PassScreen))
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in Connect(PassScreen) (at Navigation.js:83)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in Provider (at Navigation.js:82)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in _class2 (at renderApplication.js:35)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in RCTView (at View.js:78)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in View (at AppContainer.js:102)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in RCTView (at View.js:78)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in View (at AppContainer.js:122)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native:     in AppContainer (at renderApplication.js:34)
05-17 12:30:13.796  5343 10283 I bugsnag-react-native: Notifying native client, severity = error, severityReason = unhandledException
05-17 12:30:13.796  5343 10283 I Bugsnag : Internal client notify, severity = 'error', severityReason = 'unhandledException'
05-17 12:30:13.807  5343 10283 I bugsnag-react-native: Notified native client

How to add google wallet pass using JWTToken

Hello
I'm implementing adding health cards to my google wallet app in android for my react native application. I was able to generate the JWTToken from google wallet web api's, now I have JWTToken with all the pass data which looks like this

https://pay.google.com/gp/v/save/eyfesiufgheiufrhUKYGBUYguygfYUGUGYETerggewtretetewwere
this is how my googlewallet pass token looks like.

Now Does this package works for android if I convert the jwtoken into base64 ? will it show the android pass to add on the device ?

Expanded example?

Can you expand on how a pass should be added? The example in the README is simply:

PassKit.addPass(base64EncodedPass)

Does this mean that we should generate a signed pass (ending in .pkpass) and then base64 encode that file's contents?

I've tried that only to get a generic "Adding pass error".

Example App

Hello there,

Are there any sample projects on how to use the library?

ANDROID: "unknown:ReactNative: com.facebook.react.bridge.NativeArgumentsParseException: RNPassKit.addPass got 3 arguments, expected 4"

Hello, I have systematically a crash when using with Android after checking that the method "canAddPass" from the library returns true.

React Native version : 0.59.8

I added the last version of this library (not released yet), here is the realted line in my package.json:

"react-native-passkit-wallet": "git://github.com/miyabi/react-native-passkit-wallet.git"

06-03 11:20:11.490 26956 27045 E unknown:ReactNative: Exception in native call
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: com.facebook.react.bridge.NativeArgumentsParseException: RNPassKit.addPass got 3 arguments, expected 4
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:353)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:790)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:164)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
06-03 11:20:11.490 26956 27045 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:764)

Can you help me with this please ?

Thank you

IOS: Wallet Integration Issue

I am integration Add to Wallet feature in my React native App. I have installed the package and while testing on device, getting an error

"Possible Unhandled Promise Rejection (id: 3):
Error: Failed to create pass."

Please give a proper documentation if i am missing something.
Thanks.

Add to pass button?

The add to pass button does not include the standard Apple image. The documentation does not show what values you have for {styles.addPassButton}

I have these styles and I can't see any wallet image on the button:

	addPassButton: {
		marginTop: 100,
		height: PassKit.AddPassButtonHeight,
		width: PassKit.AddPassButtonWidth
	}

Need a working example

I am unable to find information in the doc regarding how to implement add to wallet. What is base64EncodedPass? Can somebody please post working example on this?

iOS linking not working

installed it on with yarn and when i tried to import the xcode project, xcode complains because it cannot open the project file, any help ?

NFC Features

Hello there 👋
Thanks for your hard work!

I'd like to know if I can use the NFC feature on the Apple Wallet when I add the pass to it.

For instance, can I add an access key to unlock a smart lock?

Thanks!

CanAddPasses doesn't work on Android

I made the AndroidX changes needed in the AndroidManifest and I used this code to add the wallet in my phone:

  const handleOnPress = async () => {
    PassKit.canAddPasses().then(async () => {
      await PassKit.addPass(
        idCardPassBase64,
        '$bundleId.fileprovider',
      )
    })
  }

Current Behavior


If I don't have a PKPass reading app installed, it still goes ahead and tries to add a pass on Android and throws an error:

Error: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://$bundleId.fileprovider/passkit/4aff4a73-9774-4c3b-8538-f0ab8439c7b2.pkpass typ=application/vnd.apple.pkpass flg=0x10000001 }

But if I have the app installed, it works fine and adds the pass to the wallet.

Expected Behavior:


  • CanAddPasses should return false and not actually try adding the pass.

Note: $bundleId is my app's bundle ID.

Add multiple tickets at once

Is there a way to add multiple tickets at once or there are any plans on changing this library to support that?

React Native 0.68 Android Build Error

Getting the following error when ever I run npm run android in the terminal, anyone have any recommendations?:

> Configure project :app
Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version. Class name for the included build object: org.gradle.composite.internal.DefaultIncludedBuild$IncludedBuildImpl_Decorated.
Reading env from: .env

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
6 actionable tasks: 6 up-to-date

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/react-native-passkit-wallet/android/build.gradle' line: 16

* What went wrong:
A problem occurred evaluating project ':react-native-passkit-wallet'.
> Could not find method provided() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/react-native-passkit-wallet/android/build.gradle' line: 16

* What went wrong:
A problem occurred evaluating project ':react-native-passkit-wallet'.
> Could not find method provided() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s

    at makeError (/Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/execa/index.js:174:9)
    at /Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/saamer/Documents/GitHub/GSC-RN/gsc-mobile/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.

Is this repo dead?

@miyabi Is this repository still maintained?

The work that has been done so far is amazing, especially because it is the only package that can add passes on Android—at least as far as I know. But it could use a do-over. The three PR's #9, #16, and #17 could easily be merged, and on Android side the project should be migrated to AndroidX. I would also offer to help out because I would like this package to be up-to-date, but at the moment there's just nothing happening at all.

“Native module cannot be null”

Hello, I'm trying to implement PassKit wallet to my app. I'm using expo, so. where is no iOS Android folders, so I'm getting this error “Native module cannot be null”, This error is located in PassKit.ios.js on line 10.
After this I detached app and implemented everything like in. manual but getting same error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.