小程序模板網(wǎng)

iOS分享微信小程序

發(fā)布時(shí)間:2018-05-30 11:27 所屬欄目:小程序開發(fā)教程

最近項(xiàng)目中遇到了APP分享微信小程序,記錄下來(lái)問(wèn)題,希望能幫助到需要的人

項(xiàng)目中的分享集成的是第三方的友盟,我看了下微信官方的sdk和友盟的小程序分享差不多,于是,就先羅列下友盟的分享

1.首先在微信開放平臺(tái)添加移動(dòng)應(yīng)用,審核通過(guò)了就可以使用

2.在同一開放平臺(tái)賬號(hào)下的移動(dòng)應(yīng)用及小程序無(wú)需關(guān)聯(lián)即可完成跳轉(zhuǎn),非同一開放平臺(tái)賬號(hào)下的小程序需與移動(dòng)應(yīng)用(APP)成功關(guān)聯(lián)后才支持跳轉(zhuǎn)。

3.如果不在同一開放平臺(tái)賬號(hào),后臺(tái)需要綁定,打開移動(dòng)應(yīng)用詳情,拉到最下面,如果未關(guān)聯(lián),會(huì)看到關(guān)聯(lián)小程序按鈕,點(diǎn)擊進(jìn)入,填寫相關(guān)信息,關(guān)聯(lián)即可

已關(guān)聯(lián)小程序 
4.點(diǎn)擊小程序模塊,會(huì)看到"綁定小程序"按鈕,這個(gè)是有限制的,上面已經(jīng)有顯示

綁定小程序 
5.綁定完之后,點(diǎn)擊詳情,可以查看到一些信息,比如 "原始ID",后面demo里面需要使用,后面的小程序頁(yè)面路徑及其他需要的信息,找你們的小程序開發(fā)者要就可以了

6.接下來(lái)上代碼:

 

  1. - (void)shareMiniProgramToPlatformType:(UMSocialPlatformType)platformType
  2. {
  3. //創(chuàng)建分享消息對(duì)象
  4. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  5. UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:@"小程序標(biāo)題" descr:@"小程序內(nèi)容描述" thumImage:[UIImage imageNamed:@"icon"]];
  6. shareObject.webpageUrl = @"兼容微信低版本網(wǎng)頁(yè)地址";
  7. shareObject.userName = @"小程序username,如 gh_3ac2059ac66f";
  8. shareObject.path = @"小程序頁(yè)面路徑,如 pages/page10007/page10007";
  9. messageObject.shareObject = shareObject;
  10. shareObject.hdImageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]];
  11. shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; // 可選體驗(yàn)版和開發(fā)板
  12. //調(diào)用分享接口
  13. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  14. if (error) {
  15. UMSocialLogInfo(@"************Share fail with error %@*********",error);
  16. }else{
  17. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  18. UMSocialShareResponse *resp = data;
  19. //分享結(jié)果消息
  20. UMSocialLogInfo(@"response message is %@",resp.message);
  21. //第三方原始返回的數(shù)據(jù)
  22. UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
  23. }else{
  24. UMSocialLogInfo(@"response data is %@",data);
  25. }
  26. }
  27. [self alertWithError:error];
  28. }];
  29. }

微信小程序分享目前只支持會(huì)話分享,不支持朋友圈和收藏類型的分享


本文地址:http://m.u-renovate.com/wxmini/doc/course/24482.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×