iOS Developer Guide

View Markdown

Last edited on 2026-07-28

This article introduces how to implement WeChat sharing and favorites features in iOS mobile applications.

1. Multi-platform Application Development Guide

To reduce the development cost for developers building mobile applications, the platform has introduced a multi-platform framework implemented with Mini Program technology. This framework enables the cost-effective development of Android and iOS apps. For more details, see Overview of Multi-platform Framework. If your App is developed using the official multi-platform framework, you can call the following JSAPIs to implement WeChat sharing and favoriting features within your App.

2. Guide for Non-Cross-Platform App Development

If your App is not developed using a cross-platform framework, you can follow the guidelines below to integrate the WeChat SDK into your App and call APIs to enable WeChat sharing and favoriting features. The following sections provide examples for sharing text, images, videos, web pages, Mini Program, music videos, and files.

WXMediaMessage (WeChat Media Message Content) Description

Field Type Description Remarks
title NSString Message title Length limit: no more than 512 Bytes
description NSString Description content Length limit: no more than 1KB
thumbData NSData Binary data of the thumbnail Content size limit: no more than 32KB
mediaObject NSObject Multimedia data object Can be WXImageObject, WXMusicVideoObject, WXVideoObject, WXWebpageObject, WXFileObject, etc.
messageExt NSString Additional information When mediaObject is WXMusicVideoObject, returning from the WeChat music player will include this parameter. The length must not exceed 2k. (Must be consistent across iOS and Android platforms)
thumbDataHash NSString SHA256 hash of the message thumbnail data Used for signing. See OpenSDK Share Signature Development Guide for details
msgSignature NSString Message signature See OpenSDK Share Signature Development Guide for details

SendMessageToWXReq (SendMessageToWX request class)

The target scenario for sharing or saving to favorites is determined by modifying the scene field of SendMessageToWXReq.

Field Type Description Remarks
text NSString The text content of the message
bText BOOL Whether the message is text-based The type of message to send. It can be either a text message or a multimedia message. You must choose one; sending both text and multimedia messages simultaneously is not supported.
message WXMediaMessage The multimedia content of the message
scene int The target scenario for sending Share to session:
WXSceneSession
Share to Moments:
WXSceneTimeline
Save to Favorites:
WXSceneFavorite

Examples

1. Text Type Sharing Example

SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = YES;
req.text = @"Shared Content";
req.scene = WXSceneSession;
[WXApi sendReq:req];

2. Image Type Sharing Example

WXImageObject: The image data object contained in a multimedia message

Field Type Description Remarks
imageData NSData Binary data of the image Content size must not exceed 10MB
imgDataHash NSString SHA256 of the image binary data Used for signing. See OpenSDK Share Signing Developer Guide for details
entranceMiniProgramUsername NSString Mini Program username to launch Determines whether the shared image message includes a Mini Program entry. If not empty, the entry is displayed. Supported in OpenSDK 2.0.4. Minimum client version required: 8.0.48
entranceMiniProgramPath NSString Mini Program path to launch The Mini Program path that the Mini Program entry in the shared image message can redirect to. Supported in OpenSDK 2.0.4. Minimum client version required: 8.0.48
UIImage *image = [UIImage imageNamed:@"res2.png"];
imageData = UIImageJPEGRepresentation(image, 0.7);

WXImageObject *imageObject = [WXImageObject object];
imageObject.imageData = imageData;

WXMediaMessage *message = [WXMediaMessage message];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"res5"
 ofType:@"jpg"];
message.thumbData = [NSData dataWithContentsOfFile:filePath];
message.mediaObject = imageObject;

SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneTimeline;
[WXApi sendReq:req];

3. Video Type Sharing Example

WXVideoObject: The video data object contained in a multimedia message

Field Type Description Remarks
videoUrl NSString Video URL Length must not exceed 10KB
videoLowBandUrl NSString Video URL for low-bandwidth environments Length must not exceed 10KB

Note: videoUrl and videoLowBandUrl cannot both be empty

WXVideoObject *videoObject = [WXVideoObject object];
videoObject.videoUrl = @"Video URL";
videoObject.videoLowBandUrl = @"Low-resolution Video URL";
WXMediaMessage *message = [WXMediaMessage message];
message.title = @"Title";
message.description = @"Description";
[message setThumbImage:[UIImage imageNamed:@"thumbnail.jpg"]];
message.mediaObject = videoObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req];

4. Webpage Type Sharing Example

WXWebpageObject: The webpage data object contained in a multimedia message

Field Type Description Remarks
webpageUrl NSString HTML link Length must not exceed 10KB
WXWebpageObject *webpageObject = [WXWebpageObject object];
webpageObject.webpageUrl = @"https://open.weixin.qq.com";
WXMediaMessage *message = [WXMediaMessage message];
message.title = @"Title";
message.description = @"Description";
[message setThumbImage:[UIImage imageNamed:@"thumbnail.jpg"]];
message.mediaObject = webpageObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req];

5. Mini Program Type Sharing Example

WXMiniProgramObject: The Mini Program data object contained in a multimedia message

Field Type Description Notes
webpageUrl NSString Webpage link compatible with older versions Length limit: 10KB
userName NSString Mini Program userName Method to obtain the Mini Program original ID: Log in to the Mini Program Management Backend - Settings - Basic Settings - Account Info
path NSString Page path of Mini Program Mini Program page path; for Mini Games, you can pass only the query part to achieve parameter passing, e.g., passing "?foo=bar"
hdImageData NSData Binary data for the preview image in the new version of Mini Program, supported by WeChat client version 6.5.9 and above Size limit: 128KB. It is recommended that custom images have an aspect ratio of 5:4
withShareTicket BOOL Whether to use sharing with shareTicket Developers usually want to retrieve more information, such as group identifiers, when a shared Mini Program is opened a second time. You can set withShareTicket to true. When the share card is opened by other users in a group chat, the shareTicket can be retrieved to obtain more sharing information. See Mini Program Retrieve More Sharing Information for details. Minimum client version requirement: 6.5.13
miniprogramType WXMiniProgramType Type of Mini Program, default is the official release. Developer tool packages version 1.8.1 and above support sharing development and trial versions of Mini Program Official release: WXMiniProgramTypeRelease
Test version: WXMiniProgramTypeTest
Preview version: WXMiniProgramTypePreview
WXMiniProgramObject *object = [WXMiniProgramObject object];
object.webpageUrl = webpageUrl;
object.userName = userName;
object.path = path;
object.hdImageData = hdImageData;
object.withShareTicket = withShareTicket;
object.miniProgramType = programType;
WXMediaMessage *message = [WXMediaMessage message];
message.title = @" Mini Program Title";
message.description = @" Mini Program Description";
message.thumbData = nil; // Image for backward compatibility with older versions, less than 32KB. Newer versions prioritize
 // using the hdImageData property of WXMiniProgramObject
message.mediaObject = object;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req];

6. Example of Sharing Music Video Type

This type requires OpenSDK version 1.8.9 or above

WXMusicVideoObject is the music video data object contained in multimedia messages.

Field Type Description Notes
musicUrl NSString URL of the audio webpage Required. Length limit: 10KB
musicDataUrl NSString URL of the audio data Required. Length limit: 10KB
singerName NSString Singer name Required. Length limit: 1KB
duration UInt32 Music duration (song length) Required. Cannot be 0. Unit: milliseconds
hdAlbumThumbData NSData High-definition album cover image Optional. Size limit: 1MB
albumName NSString Music album name Optional
songLyric NSString Lyric information in LRC format Optional. Length limit: 32K
musicGenre NSString Music genre Optional
issueDate UInt64 Release time (Unix timestamp) Optional. Unit: seconds
identification NSString Music identifier Optional but recommended. When the user jumps back from the WeChat music player to the app, this parameter will be included. It can be used to uniquely identify a song. WeChat does not interpret its meaning (must be consistent across iOS and Android platforms)
hdAlbumThumbFileHash NSString SHA256 hash of the high-definition album cover image Used for signing. See OpenSDK Sharing Signature Development Manual for details

Send MV to WeChat:

WXMusicVideoObject *mvObject = [WXMusicVideoObject object];
mvObject.musicUrl = @"Music url";
mvObject.musicDataUrl = @"Music data url";
mvObject.singerName = @"Singer name";
mvObject.duration = 60 * 1000; // Music duration, milliseconds
mvObject.hdAlbumThumbData = hdAlbumThumbData; // High-definition album cover image
mvObject.albumName = @"Album name";
mvObject.musicGenre = @"Music genre";
mvObject.issueDate = 1611116532; // Release time Unix timestamp
mvObject.identification = @"test-identification"; // Music identifier

WXMediaMessage *message = [WXMediaMessage message];
message.title = @"Song name"; // Required, cannot be empty
message.messageExt = @"Additional info"; // Included when jumping back to WeChat

[message setThumbImage:[UIImage imageNamed:@"thumbnail.jpg"]];
message.mediaObject = mvObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req];

Handling the jump back from the WeChat music player:

#pragma mark - WXApiDelegate

- (void)onReq:(BaseReq *)req {
    if ([req isKindOfClass:[LaunchFromWXReq class]]) {
        LaunchFromWXReq *launchReq = (LaunchFromWXReq *)req;
        NSString* messageExt = launchReq.message.messageExt;  // Pass-through extra information field when sharing to WeChat
        if ([launchReq.message.mediaObject isKindOfClass:WXMusicVideoObject.class]) {
            WXMusicVideoObject *musicVideoObject = (WXMusicVideoObject *)launchReq.message.mediaObject;
            NSString *identification = musicVideoObject.identification; // Music identifier field when sharing to WeChat
            // The app can process logic based on messageExt and identification
        }
    }
}

Instructions for using the music video type:

  1. Precautions:
    • The music video type is different from the music type. For music video messages shared to WeChat, clicking directly on the shared content in a friend's chat or Moments will redirect to the native WeChat player. You can create music videos by combining music works with videos, allowing users to like, comment, send to friends, share to Moments, publish to Video Accounts, etc.
    • Clicking the jump entry inside the player redirects back to the App. If the App is not installed, the musicUrl link will be opened.
  2. For sharing music video types, developers must pay special attention to the following required fields:
    • WXMediaMessage.title: Song name
    • WXMusicVideoObject.musicUrl: URL address of the audio web page
    • WXMusicVideoObject.musicDataUrl: URL address of the audio data
    • WXMusicVideoObject.singerName: Singer name
    • WXMusicVideoObject.duration: Song duration, in milliseconds
  3. The WXMediaMessage.messageExt field set by third-party apps during sharing and WXMusicVideoObject.identification must be consistent across Android and iOS platforms. Otherwise, there is no guarantee that cross-platform shared messages can jump back to the corresponding song in the App.
  4. Regardless of the type of WXMediaMessage.mediaObject, the WXMediaMessage.messgeExt field will always pass through the data written by the app during sharing. The app can use this field for compatibility handling of older app versions.

7. File Type Sharing Example (including PDF)

WXFileObject is used for sharing general files. PDF is just an example and is not the only supported format.

Field Type Description Notes
fileExtension NSString * File extension Not exceeding 64 bytes; enter pdf for PDF examples
fileData NSData * File data Not exceeding 10MB

Example of sharing a PDF to a session:

NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
if (pdfData == nil) {
    return;
}

WXFileObject *fileObject = [WXFileObject object];
fileObject.fileExtension = @"pdf";
fileObject.fileData = pdfData;

WXMediaMessage *message = [WXMediaMessage message];
message.title = @"example.pdf";
message.mediaObject = fileObject;

SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req completion:^(BOOL success) {
    // success indicates whether the request was initiated successfully; the final result is based on the OpenSDK callback
}];

File size and target scenarios are also subject to the WeChat client version and runtime validation; please check fileData and the file extension before sending.

Notes

  1. The App initiating the share and the Mini Program must belong to the same WeChat Open Platform account.
  2. Alternatively, if the App initiating the share and the third-party platform account of the service provider developing on behalf of the Mini Program (i.e., holding authorization with permission ID 18 for the Mini Program) belong to the same WeChat Open Platform account, sharing is also supported.
  3. You can share the Mini Program card directly to a conversation. However, sharing to Moments will open Single Page Mode. Please ensure your development is compatible with this behavior.
  4. If the client version is lower than 6.5.6 or if the content is received on the iPad client, the Mini Program type share will automatically be converted into a web page type share. Developers must fill in the web page link field to ensure that lower-version clients can open the web page link properly.
  5. For sharing music video types, you must send an email to hansenxu@tencent.com in the following format:
  • Email Subject: Application for Music Video Appmsg Sharing Feature for Account XXX;
  • Email Content: Please provide the mobile app appid and the domain information of the web page containing the audio to be shared;
  • Requirements:
  • The applying account must have completed entity verification;
  • To apply for the "Music Video Type Sharing Permission," you must first have obtained the "Music Type Sharing Permission." Additionally, the appid of the mobile app and the domain must match;
  • The Music Video Type Sharing Permission involves signing relevant legal agreements. Please refer to the email reply for the specific signing process and activation result.