Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Cannot create Factors #17

Open
tonyjaimep opened this issue Feb 16, 2022 · 7 comments
Open

iOS: Cannot create Factors #17

tonyjaimep opened this issue Feb 16, 2022 · 7 comments

Comments

@tonyjaimep
Copy link

Description

As the title suggests, I'm getting an error when I try creating Factors, the error log is provided below

I'm using a physical iOS device, and getting this error both in my own app and in the provided example app.
It may be worth noting that I'm not using the sample backend. I'm hard-coding the values I'm getting in my own app into the example app.

Steps to Reproduce

  1. Create a RN App or install the example app
  2. Try creating a factor
  3. See the error (if using the example app, it will be displayed in a native alert, otherwise you may need to console.log it using JSON.stringify.

Expected Behavior

Verification factors can be created in iOS devices

Demo Project

I am able to reproduce this issue in the example app.

Versions

  • SDK version: Irrelevant
  • iOS version: 15.2.1
  • Device: iPhone XS
  • IDE version: Irrelevant
  • React native version: 0.64.1 (version in example app).

Log

 [
  "0   RNTwilioVerifyExample               0x000000010084c720 RCTJSErrorFromCodeMessageAndNSError + 116",
  "1   RNTwilioVerifyExample               0x00000001007e83a8 __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.129 + 144",
  "2   RNTwilioVerifyExample               0x0000000100ad93ec $sSo8NSStringCSgACSo7NSErrorCSgIeyByyy_SSSgAGs5Error_pSgIegggg_TR + 320",
  "3   RNTwilioVerifyExample               0x0000000100ad8fd4 $s30twilio_verify_for_react_native14RNTwilioVerifyC12createFactor13factorPayload7resolve6rejectySDyS2SG_yypSgcySSSg_AJs5Error_pSgtctFy06TwilioG3SDK0ogN0OcfU0_ + 444",
  "4   RNTwilioVerifyExample               0x0000000100a8420c $s15TwilioVerifySDK11PushFactoryC12createFactor15withAccessToken12friendlyName04pushJ010serviceSid8identity7success7failureySS_S4SyAA0G0_pcyAA0aB5ErrorOctFys0S0_pcfU0_ + 384",
  "5   RNTwilioVerifyExample               0x0000000100a75478 $s15TwilioVerifySDK14NetworkAdapterC7execute_7success7failurey10Foundation10URLRequestV_yAA8ResponseVcys5Error_pctFys6ResultOyAKsAL_pGcfU0_ + 652",
  "6   RNTwilioVerifyExample               0x0000000100a95040 $sSo12NSURLSessionC15TwilioVerifySDKE8dataTask4with6resultSo0a4DataF0C10Foundation10URLRequestV_ys6ResultOyAC8ResponseVs5Error_pGctFyAI0I0VSg_So13NSURLResponseCSgsAP_pSgtcfU_ + 4328",
  "7   RNTwilioVerifyExample               0x0000000100a953cc $s10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIegggg_So6NSDataCSgAGSo7NSErrorCSgIeyByyy_TR + 240",
  "8   RNTwilioVerifyExample               0x00000001005c8614 __79+[FLEXNetworkObserver asyncCompletionWrapperForRequestID:mechanism:completion:]_block_invoke + 952",
  "9   CFNetwork                           0x0000000181d030ac CFURLRequestSetMainDocumentURL + 3028",
  "10  CFNetwork                           0x0000000181d14054 _CFNetworkErrorCopyLocalizedDescriptionWithHostname + 11444",
  "11  libdispatch.dylib                   0x00000001032e86d4 _dispatch_call_block_and_release + 32",
  "12  libdispatch.dylib                   0x00000001032ea3b4 _dispatch_client_callout + 20",
  "13  libdispatch.dylib                   0x00000001032f2540 _dispatch_lane_serial_drain + 988",
  "14  libdispatch.dylib                   0x00000001032f32c4 _dispatch_lane_invoke + 480",
  "15  libdispatch.dylib                   0x00000001032ffe20 _dispatch_workloop_worker_thread + 916",
  "16  libsystem_pthread.dylib             0x00000001f1f370f4 _pthread_wqthread + 288",
  "17  libsystem_pthread.dylib             0x00000001f1f36e94 start_wqthread + 8"
]
@yafuquen
Copy link
Collaborator

@tonyjaimep Is this happening only for iOS? Also, please take into account that the access token's TTL is 1 minute, you will need to generate a new one before running the app when hard-coding the value

@tonyjaimep
Copy link
Author

tonyjaimep commented Feb 21, 2022

@yafuquen yes, only for iOS.
About the token's TTL: I'll try again to see if that's where the issue lies. Will update with results.

Update

That's apparently not the issue since the factor is being created almost immediately after generating the token

 LOG  Got Access Token @ 2022-02-21T15:21:48.762Z
 LOG  Creating Twilio Verify Factor @ 2022-02-21T15:21:48.775Z

@tonyjaimep
Copy link
Author

After inspecting the network request generated by twilio-verify-for-react-native I see that Config.NotificationPlatform is set to apn, but I'm sending Config.NotificationToken as the token provided by react-native-firebase (messaging().getToken()).
If that's the issue, the question now would be: which token should I use for iOS instead of the one provided by fcm?

@tonyjaimep
Copy link
Author

What if I want to use FCM instead of APNs for iOS?

@yafuquen
Copy link
Collaborator

yafuquen commented Feb 21, 2022

Currently, we only support APNs for iOS, you can see an example here. Our example app is using react-native-push-notification

@irvingAlto
Copy link

I am facing the same problem but I using react-native-notifications to handle the APN token however I getting the error : Error while calling the API when call TwilioVerify.createFactor

This is my code:

  const accessTokenResponse = await getTwilioVerifyAccessToken(identity)
  const hashedIdentity = accessTokenResponse.identity
  const accessToken = accessTokenResponse.token
  
  if (Platform.OS === 'ios') {
  Notifications.registerRemoteNotifications()
  Notifications.events().registerRemoteNotificationsRegistered(
    async (event) => {
      const pushToken = event.deviceToken
      try {
        let factor = await TwilioVerify.createFactor(
          new PushFactorPayload(
            deviceName || 'Mobile Device',
            Config.TWILIO_VERIFY_SERVICE_SID,
            hashedIdentity,
            pushToken,
            accessToken
          )
        )
        if (!factor.sid) throw new Error('Created factor has no SID')
        return factor
      } catch (error) {
        console.log('error', error)
      }
    }
  )
  await Notifications.events().registerRemoteNotificationsRegistrationFailed(
    (event) => {
      console.log('Notification error', event)
    }
  )
  }```


React native: `0.68.5`

@yafuquen
Copy link
Collaborator

@irvingAlto Could you confirm the push react native library you are using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants