標籤:
因為一開始是按照新浪的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 整合一下代碼也可以 不再舉例了。
解決新浪微博未安裝用戶端分享不能帶連結問題