友盟集成(五) —— UShare模塊之進階說明之分享到第三方平臺(二)

版本記錄

版本號 時間
V1.0 2018.04.05

前言

相信很多人用過友盟描滔,包括友盟的第三方登錄、分享以及統(tǒng)計踪古。這里我們就分幾個模塊進行詳細的說明 —— 移動統(tǒng)計(U - App)含长、網(wǎng)站統(tǒng)計(U - Web)、消息推送(U - Push)伏穆、社會化分享(U - Share)拘泞、游戲統(tǒng)計(U - Game)、互聯(lián)網(wǎng)運營數(shù)據(jù)服務(Dplus) - 多維度枕扫、一站式陪腌、精細化數(shù)據(jù)管理服務。感興趣的可以看上面幾篇烟瞧。
1. 友盟集成(一) —— UShare模塊之快速集成(一)
2. 友盟集成(二) —— UShare模塊之快速集成(二)
3. 友盟集成(三) —— UShare模塊之第三方登錄(一)
4. 友盟集成(四) —— UShare模塊之進階說明之第三方平臺SDK說明(一)

分享到第三方平臺

1. 第三方平臺支持的分享類型總覽

2. 分享文本

- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //設置文本
    messageObject.text = @"社會化組件UShare將各大社交平臺接入您的應用诗鸭,快速武裝App。";

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

3. 分享圖片

- (void)shareImageToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //創(chuàng)建圖片內(nèi)容對象
    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
    //如果有縮略圖参滴,則設置縮略圖
    shareObject.thumbImage = [UIImage imageNamed:@"icon"];
    [shareObject setShareImage:@"https://mobile.umeng.com/images/pic/home/social/img-1.png"];

    //分享消息對象設置分享內(nèi)容對象
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

4. 分享圖文(新浪支持强岸,微信/QQ僅支持圖或文本分享)

- (void)shareImageAndTextToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //設置文本
    messageObject.text = @"社會化組件UShare將各大社交平臺接入您的應用,快速武裝App卵洗。";

    //創(chuàng)建圖片內(nèi)容對象
    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
    //如果有縮略圖请唱,則設置縮略圖
    shareObject.thumbImage = [UIImage imageNamed:@"icon"];
    [shareObject setShareImage:@"https://www.umeng.com/img/index/demo/1104.4b2f7dfe614bea70eea4c6071c72d7f5.jpg"];

    //分享消息對象設置分享內(nèi)容對象
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

5. 分享網(wǎng)頁

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //創(chuàng)建網(wǎng)頁內(nèi)容對象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享標題" descr:@"分享內(nèi)容描述" thumImage:[UIImage imageNamed:@"icon"]];
    //設置網(wǎng)頁地址
    shareObject.webpageUrl =@"http://mobile.umeng.com/social";

    //分享消息對象設置分享內(nèi)容對象
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

6. 分享音樂

- (void)shareMusicToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //創(chuàng)建音樂內(nèi)容對象
    UMShareMusicObject *shareObject = [UMShareMusicObject shareObjectWithTitle:@"分享標題" descr:@"分享內(nèi)容描述" thumImage:[UIImage imageNamed:@"icon"]];
    //設置音樂網(wǎng)頁播放地址
    shareObject.musicUrl = @"http://c.y.qq.com/v8/playsong.html?songid=108782194&source=yqq#wechat_redirect";
    //            shareObject.musicDataUrl = @"這里設置音樂數(shù)據(jù)流地址(如果有的話弥咪,而且也要看所分享的平臺支不支持)";
    //分享消息對象設置分享內(nèi)容對象
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

7. 分享視頻

- (void)shareVedioToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    //創(chuàng)建視頻內(nèi)容對象
    UMShareVideoObject *shareObject = [UMShareVideoObject shareObjectWithTitle:@"分享標題" descr:@"分享內(nèi)容描述" thumImage:[UIImage imageNamed:@"icon"]];
    //設置視頻網(wǎng)頁播放地址
    shareObject.videoUrl = @"http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html";
    //            shareObject.videoStreamUrl = @"這里設置視頻數(shù)據(jù)流地址(如果有的話,而且也要看所分享的平臺支不支持)";

    //分享消息對象設置分享內(nèi)容對象
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}

8. 分享微信表情

- (void)shareEmoticonToPlatformType:(UMSocialPlatformType)platformType
{
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    UMShareEmotionObject *shareObject = [UMShareEmotionObject shareObjectWithTitle:UMS_Title descr:UMS_Text thumImage:nil];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"gifFile"
                                                         ofType:@"gif"];
    NSData *emoticonData = [NSData dataWithContentsOfFile:filePath];
    shareObject.emotionData = emoticonData;
    messageObject.shareObject = shareObject;

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享結(jié)果消息
                NSLog(@"response message is %@",resp.message);

            }else{
                NSLog(@"response data is %@",data);
            }
        }
    }];
}

9. 分享微信小程序

- (void)shareMiniProgramToPlatformType:(UMSocialPlatformType)platformType
{
    //創(chuàng)建分享消息對象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:@"小程序標題" descr:@"小程序內(nèi)容描述" thumImage:[UIImage imageNamed:@"icon"]];
    shareObject.webpageUrl = @"兼容微信低版本網(wǎng)頁地址";
    shareObject.userName = @"小程序username十绑,如 gh_3ac2059ac66f";
    shareObject.path = @"小程序頁面路徑聚至,如 pages/page10007/page10007";
    messageObject.shareObject = shareObject;
    shareObject.hdImageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]];
    shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; // 可選體驗版和開發(fā)板

    //調(diào)用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享結(jié)果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的數(shù)據(jù)
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);

            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        [self alertWithError:error];
    }];
}

10. 示例

分享文本到微信

#import <UMShare/UMShare.h>

- (void)shareTextToWechat
{
    NSString *text = @"社會化組件U-Share將各大社交平臺接入您的應用,快速武裝App本橙。";

    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

    messageObject.text = text;

    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        NSString *message = nil;
        if (!error) {
            message = [NSString stringWithFormat:@"分享成功"];
        } else {
            message = [NSString stringWithFormat:@"失敗原因Code: %d\n",(int)error.code];

        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
                                                        message:message
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@"確定", nil)
                                              otherButtonTitles:nil];
        [alert show];
    }];
}

調(diào)用分享面板分享文本到所選平臺

#import <UShareUI/UShareUI.h>
#import <UMShare/UMShare.h>

- (void)shareWithUI {

    //顯示分享面板
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根據(jù)獲取的platformType確定所選平臺進行下一步操作

        //創(chuàng)建分享消息對象
        UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
        //設置文本
        messageObject.text = @"社會化組件UShare將各大社交平臺接入您的應用扳躬,快速武裝App。";

        //調(diào)用分享接口
        [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
            if (error) {
                NSLog(@"************Share fail with error %@*********",error);
            }else{
                NSLog(@"response data is %@",data);
            }
        }];
    }];
}

后記

本篇主要介紹了分享的類型以及示例代碼甚亭,感興趣的給個贊或者關(guān)注~~~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末贷币,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子亏狰,更是在濱河造成了極大的恐慌役纹,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件暇唾,死亡現(xiàn)場離奇詭異促脉,居然都是意外死亡,警方通過查閱死者的電腦和手機策州,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進店門瘸味,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人够挂,你說我怎么就攤上這事旁仿。” “怎么了孽糖?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵枯冈,是天一觀的道長。 經(jīng)常有香客問我梭姓,道長霜幼,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任誉尖,我火速辦了婚禮,結(jié)果婚禮上铸题,老公的妹妹穿的比我還像新娘铡恕。我一直安慰自己,他們只是感情好丢间,可當我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布探熔。 她就那樣靜靜地躺著,像睡著了一般烘挫。 火紅的嫁衣襯著肌膚如雪诀艰。 梳的紋絲不亂的頭發(fā)上柬甥,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天,我揣著相機與錄音其垄,去河邊找鬼苛蒲。 笑死,一個胖子當著我的面吹牛绿满,可吹牛的內(nèi)容都是我干的臂外。 我是一名探鬼主播,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼喇颁,長吁一口氣:“原來是場噩夢啊……” “哼漏健!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起橘霎,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤蔫浆,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后姐叁,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體克懊,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年七蜘,在試婚紗的時候發(fā)現(xiàn)自己被綠了谭溉。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡橡卤,死狀恐怖扮念,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情碧库,我是刑警寧澤柜与,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站嵌灰,受9級特大地震影響弄匕,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜沽瞭,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一迁匠、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧驹溃,春花似錦城丧、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至布疙,卻和暖如春蚊惯,著一層夾襖步出監(jiān)牢的瞬間愿卸,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工截型, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留趴荸,地道東北人。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓菠劝,卻偏偏與公主長得像赊舶,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子赶诊,可洞房花燭夜當晚...
    茶點故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容