解決新浪微博未安裝用戶端分享不能帶連結問題

來源:互聯網
上載者:User

標籤:

因為一開始是按照新浪的demo寫的,但是demo也存在這個問題當在未安裝用戶端的情況下分享的連結不會顯示。解決辦法 :

WBSendMessageToWeiboRequest 類有一個WBMessageObject 的類 這個類的text是分享的內容  在這裡設定分享內容 將分享的url加進來。代碼如下

- (void)shareButtonPressed{    AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];        WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];    authRequest.redirectURI = kRedirectURI;    authRequest.scope = @"all";        WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:[self messageToShare] authInfo:authRequest access_token:myDelegate.wbtoken];    request.userInfo = @{@"ShareMessageFrom": @"SendMessageToWeiboViewController",                         @"Other_Info_1": [NSNumber numberWithInt:123],                         @"Other_Info_2": @[@"obj1", @"obj2"],                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};    //    request.shouldOpenWeiboAppInstallPageIfNotInstalled = NO;       //判斷是否存在用戶端 不存在就這樣寫    if (![WeiboSDK isWeiboAppInstalled]) {        request.message.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"分享網頁標題", nil),@"http://sina.cn?a=1"];    }    [WeiboSDK sendRequest:request];}

messageToShare方法

- (WBMessageObject *)messageToShare{    WBMessageObject *message = [WBMessageObject message];        if (self.textSwitch.on)    {        message.text = NSLocalizedString(@"測試通過WeiboSDK發送文字到微博!", nil);    }        if (self.imageSwitch.on)    {        WBImageObject *image = [WBImageObject object];        image.imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image_1" ofType:@"jpg"]];        message.imageObject = image;    }        if (self.mediaSwitch.on)    {        WBWebpageObject *webpage = [WBWebpageObject object];        webpage.objectID = @"identifier1";        webpage.title = NSLocalizedString(@"分享網頁標題", nil);        webpage.description = [NSString stringWithFormat:NSLocalizedString(@"分享網頁內容簡介-%.0f", nil), [[NSDate date] timeIntervalSince1970]];        webpage.thumbnailData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image_2" ofType:@"jpg"]];        webpage.webpageUrl = @"http://sina.cn?a=1";        message.mediaObject = webpage;    }        return message;}

當然如果在 messageToShare 整合一下代碼也可以 不再舉例了。

 

解決新浪微博未安裝用戶端分享不能帶連結問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.