先貼出一個鏈接:https://developer.umeng.com/docs/66632/detail/66825
友盟的開發文檔
1.首先引入友盟集成
ng-click=“ctrl.shareProduct(targetCode)”; //targetCode爲要區分的類型,自定義~
/**
* 執行分享操作
* @param {number} targetCode - 分享類型碼
*/
share: function(targetCode) {
if (targetCode === SHARE_TARGET.COPY_LINK) {
//複製鏈接分享
ctrl.copyShareUrl().then(function() {
ctrl.close();
});
} else if (targetCode === SHARE_TARGET.QRCODE) {
//二維碼分享
ctrl.showQRCode();
ctrl.close();
} else if (targetCode === SHARE_TARGET.PICTURE) {
//生成圖片分享
ctrl.goSharePicture();
ctrl.close();
} else {
//分享朋友圈,發送給好友
ctrl.close();
userService.eventMarket();
shareService.share(targetCode).finally(() => {
const backButtonHandler = $ionicPlatform.registerBackButtonAction(() => {
// 該 action 僅爲屏蔽後續操作,因此不做任何事情
}, 1000);
setTimeout(() => {
backButtonHandler();
}, 500);
});
}
},
// 定義前端自定義的分享目標類型與 umeng 原生插件中定義的目標類型名稱之間的映射關係
let umengTypeKeys = {};
umengTypeKeys[SHARE_TARGET.WECHAT_FIREND] = 'wxsession';
umengTypeKeys[SHARE_TARGET.WECHAT_TIMELINE] = 'wxtimeline';
umengTypeKeys[SHARE_TARGET.QQ] = 'qq';
umengTypeKeys[SHARE_TARGET.QZONE] = 'qzone';
umengTypeKeys[SHARE_TARGET.SINA_WEIBO] = 'sina';
/**
* 將當前所設置的分享信息分享到指定的第三方社交平臺
* @param {number} [targetType] - 分享目標類型,具體定義見 SHARE_TARGET
*/
share: function(targetType) {
let umengTypeKey = umengTypeKeys[targetType];
let deferred = $cmApi.defer();
if (umengTypeKey) {
umeng.shareByType(
this.shareInfo.sharetitle,
this.shareInfo.sharemessage,
this.shareInfo.sharepic,
this.shareInfo.shareurl,
umengTypeKey,
function(platform) {
deferred.resolve(platform);
}
);
} else {
deferred.reject(APP_STATE_CODE.notSupportShareType);
}
return deferred.promise;
},
/**
* 商品詳情頁分享返利生成商品邀請純圖片並分享
* @param {number} [targetType] - 分享目標類型,具體定義見 SHARE_TARGET
*/
shareProductPicture: function(targetType, pic) {
let umengTypeKey = umengTypeKeys[targetType];
let deferred = $cmApi.defer();
if (umengTypeKey) {
umeng.shareImageByType(pic, umengTypeKey, function(platform) {
deferred.resolve(platform);
});
} else {
deferred.reject(APP_STATE_CODE.notSupportShareType);
}
return deferred.promise;
},
/**
* 微信授權登錄
*/
wxlogin:function(){
umeng.login('wechat', function(result) {
return result;
});
},
主要就是用到
umeng.shareByType各種分享到
umeng.login授權登錄獲取用戶信息
umeng.shareImageByType分享純圖片