### Check Universal Link Readiness (iOS) Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Verifies the Universal Link setup for iOS, crucial for debugging authentication and deep linking. Logs suggestions or errors. ```typescript import { checkUniversalLinkReady } from 'native-wechat'; async function verifyUniversalLinkSetup() { try { const result = await checkUniversalLinkReady(); if (result.suggestion) { console.warn('Universal Link suggestion:', result.suggestion); } if (result.errorInfo) { console.error('Universal Link error:', result.errorInfo); } else { console.log('Universal Link is configured correctly'); } return result; } catch (error) { console.error('Failed to check Universal Link:', error); } } ``` -------------------------------- ### Check WeChat Installation Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Checks if the WeChat app is installed on the device. ```APIDOC ## isWechatInstalled ### Description Checks whether the WeChat app is installed on the user's device. Returns a promise that resolves to a boolean indicating WeChat installation status. ### Method `isWechatInstalled` ### Endpoint N/A (Function call) ### Response #### Success Response (Promise) - **Resolves to true** if WeChat is installed. - **Resolves to false** if WeChat is not installed. #### Response Example ```json true ``` ``` ```APIDOC ## useWechatInstalled Hook ### Description A React hook that returns a boolean state indicating whether WeChat is installed. Automatically checks installation status on mount. ### Hook `useWechatInstalled` ### Response #### Success Response (boolean) - **Returns true** if WeChat is installed. - **Returns false** if WeChat is not installed. #### Response Example ```json true ``` ``` -------------------------------- ### React Hook for WeChat Installation Status Source: https://context7.com/hector-zhuang/native-wechat/llms.txt The useWechatInstalled hook provides a reactive boolean state for WeChat installation. It automatically checks the status when the component mounts. ```typescript import { useWechatInstalled } from 'native-wechat'; import { View, Button, Text } from 'react-native'; function LoginScreen() { const hasWechatInstalled = useWechatInstalled(); return ( {hasWechatInstalled ? ( ``` -------------------------------- ### Request WeChat Payment Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Initiates a WeChat Pay payment request. The payment parameters must be generated by your backend server using WeChat's payment API. ```typescript import { requestPayment } from 'native-wechat'; // Response type for successful payment: // { // type: 'PayResp', // errorCode: 0, // errorStr: null, // data: {} // } async function processWechatPayment(orderId: string, amount: number) { try { // Step 1: Get payment parameters from your backend const paymentResponse = await fetch('https://yourapi.com/payment/wechat/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ orderId, amount }) }); const paymentParams = await paymentResponse.json(); // Backend returns: { partnerId, prepayId, nonceStr, timeStamp, sign } // Step 2: Request payment via WeChat const result = await requestPayment({ partnerId: paymentParams.partnerId, // Merchant ID prepayId: paymentParams.prepayId, // Prepay ID from WeChat nonceStr: paymentParams.nonceStr, // Random string timeStamp: paymentParams.timeStamp, // Unix timestamp as string sign: paymentParams.sign // Signature from backend }); if (result.errorCode === 0) { console.log('Payment successful!'); // Verify payment on backend await fetch('https://yourapi.com/payment/verify', { method: 'POST', body: JSON.stringify({ orderId }) }); } return result; } catch (error) { console.error('Payment failed:', error.message); throw error; } } ``` -------------------------------- ### Share Image from URL to WeChat Chat Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Shares an image from a remote URL to a WeChat chat session. The 'shareImage' function handles downloading and compression. ```typescript import { shareImage, NativeWechatConstants } from 'native-wechat'; async function shareImageToChat(imageUrl: string) { try { // Share from remote URL await shareImage({ src: 'https://example.com/images/photo.jpg', scene: NativeWechatConstants.WXSceneSession }); console.log('Image shared successfully'); } catch (error) { console.error('Failed to share image:', error); } } ``` -------------------------------- ### Share Text to WeChat Chat Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Use this function to share text content to a specific WeChat chat session. Ensure the 'native-wechat' library is imported. ```typescript import { shareText, NativeWechatConstants } from 'native-wechat'; // Available scenes from NativeWechatConstants: // - WXSceneSession: Share to chat session (friend/group) // - WXSceneTimeline: Share to Moments (朋友圈) // - WXSceneFavorite: Add to Favorites async function shareTextContent() { try { // Share to a chat session await shareText({ text: 'Check out this amazing React Native app!', scene: NativeWechatConstants.WXSceneSession }); console.log('Text shared successfully'); } catch (error) { console.error('Failed to share text:', error); } } ``` -------------------------------- ### Native WeChat Response Type and Error Handling Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Defines the standard `NativeWechatResponse` structure for consistent API error handling. Includes a generic function to process responses and handle common WeChat error codes. ```typescript import { NativeWechatResponse } from 'native-wechat'; // Generic response structure type NativeWechatResponse> = { type: string; // Response type identifier (e.g., 'SendAuthResp', 'PayResp') errorCode: number; // 0 for success, non-zero for errors errorStr: string | null; // Error description if errorCode is non-zero transaction: string | null; // Transaction identifier data: T; // Response-specific data }; // Error handling example async function handleWechatOperation( operation: () => Promise> ): Promise { try { const response = await operation(); if (response.errorCode !== 0) { // Handle WeChat-specific errors switch (response.errorCode) { case -1: console.error('Common error'); break; case -2: console.error('User cancelled'); break; case -3: console.error('Sent failed'); break; case -4: console.error('Auth denied'); break; case -5: console.error('Unsupported'); break; default: console.error(`WeChat error (${response.errorCode}): ${response.errorStr}`); } return null; } return response.data; } catch (error) { console.error('Operation failed:', error); return null; } } ``` -------------------------------- ### NativeWechatResponse Type Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Defines the standard response structure for all promisified WeChat API calls, ensuring consistent error handling and data retrieval. ```APIDOC ## NativeWechatResponse Type ### Description The standard response type returned by all promisified WeChat APIs. Provides consistent error handling and response data structure. ### Type Definition ```typescript type NativeWechatResponse> = { type: string; // Response type identifier (e.g., 'SendAuthResp', 'PayResp') errorCode: number; // 0 for success, non-zero for errors errorStr: string | null; // Error description if errorCode is non-zero transaction: string | null; // Transaction identifier data: T; // Response-specific data }; ``` ### Error Codes - **0**: Success - **-1**: Common error - **-2**: User cancelled - **-3**: Sent failed - **-4**: Auth denied - **-5**: Unsupported ### Usage Example ```typescript import { NativeWechatResponse } from 'native-wechat'; async function handleWechatOperation( operation: () => Promise> ): Promise { try { const response = await operation(); if (response.errorCode !== 0) { // Handle WeChat-specific errors switch (response.errorCode) { case -1: console.error('Common error'); break; case -2: console.error('User cancelled'); break; case -3: console.error('Sent failed'); break; case -4: console.error('Auth denied'); break; case -5: console.error('Unsupported'); break; default: console.error(`WeChat error (${response.errorCode}): ${response.errorStr}`); } return null; } return response.data; } catch (error) { console.error('Operation failed:', error); return null; } } ``` ``` -------------------------------- ### NativeWechatResponse Type Definition Source: https://github.com/hector-zhuang/native-wechat/blob/main/readme.md Defines the generic response structure for all promisified APIs in the Native WeChat library. It includes type, error codes, error messages, and the actual data payload. ```typescript export type NativeWechatResponse> = { type: string; errorCode: number; errorStr: string | null; data: T; }; ``` -------------------------------- ### Request WeChat Subscribe Message Source: https://context7.com/hector-zhuang/native-wechat/llms.txt Requests the user to subscribe to a template message. Users who subscribe can receive notifications from your service account. ```typescript import { requestSubscribeMessage, NativeWechatConstants } from 'native-wechat'; async function subscribeToOrderNotifications() { try { await requestSubscribeMessage({ scene: NativeWechatConstants.WXSceneSession, // Scene value (0 for normal) templateId: 'TEMPLATE_ID_FROM_WECHAT', // Template ID from WeChat MP platform reserved: 'order_notification' // Optional: custom reserved field }); console.log('Successfully subscribed to notifications'); } catch (error) { console.error('Failed to subscribe:', error); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.