自訂微博小尾巴(源碼+解析),源碼

來源:互聯網
上載者:User

自訂微博小尾巴(源碼+解析),源碼
前言:

自王思聰發布了那條小尾巴是 iPhone6 的微博後,  越來越多的人跟風, 把小尾巴改成了iPhone6. 但是, 沒多久, 新浪就把原先的辦法給和諧了。原先的辦法很簡單, 就是通過網頁發布窗, 手動設定app_url(也就是每個型號手機對應的key), 在這裡發布微博, 就能實現修改微博小尾巴。

比如, 下面的是iPhone5S的代碼!!
http://widget.weibo.com/dialog/PublishWeb.php?mid=&default_text=&language=zh_cn&app_src=http://widget.weibo.com/dialog/PublishWeb.php?mid=&default_text=&language=zh_cn&app_src=3G5oUM&tag=&title=%E5%8F%91%E5%B8%83%E5%BE%AE%E5%8D%9A&button=publish&re

我之前說過了. 這個方法已經被和諧了, 現在使用這個, 發出來的都是 "來自 發布窗"。

但是總是有解決辦法的。 花了兩天時間, 我寫了這個基於iOS平台的 APP, 來實現自訂修改微博小尾巴。


:

                                   


看到這裡, 如果你還想繼續學習實現方法。 歡迎繼續往下面看。 應該會有所收穫。建議先下載源碼, 對應著看。 (源碼是基於iOS的。  但是實現方法, 相應介面和資料,都是通用的)

當然, 這個介面是新浪的。所以, 什麼時候會被和諧掉. 誰也不知道。  總之, 現在能用就對了。


源碼下載連結: https://github.com/colin1994/weiboTail.git



內容包括:

  • 微博介面分析
  • UITableView + UISearchBar 使用
  • UITableView分級菜單
  • 有米廣告嵌入
一。 微博介面分析我們觀察微博尾巴, 可以得到兩大類: 手機型號和應用程式名稱。 並不存在類似QQ空間那樣, 黃磚特權的自訂。 並且, 它的藍色連結都是有效。手機型號, 我們正常發微博的時候, 如果是手機, 它會根據裝置硬體資訊, 自動顯示對應尾巴。 每個裝置, 新浪都會為它分配一個 app_url, 這個是唯一的, 包括新上市的iPhone 6 也有其對應的app_url。應用程式名稱, 就是各個在微博開發平台註冊過的應用, 每個應用都有獨立的分享連結, 在應用中分享, 就會帶上對應的尾巴。而區區分各個應用的,就是對應的appKey。好了,分析完了。下面具體看看我們實現這個功能需要做的。
1. 擷取各個手機型號的app_url。 這個我已經收集好了。 當然, 並不是全部的。 只是羅列的比較常用的。 當然, iPhone的幾種都是包括了... 裝逼必備嘛。可以直接使用。檔案格式是.plist. iOS可以直接開啟, 但是其他系統上,需要自己去讀,它的資料格式是XML。 讀取應該是沒有問題的。 至於如何擷取, 方法如下: 1, 百度收集。 2.右鍵微博, 查看連結。
2. 手機型號調用方法。之前的方法, 是調用發布窗, 但是這個已經被和諧了。   同樣的, 我嘗試調用“話題窗”,發現這個功能還是可以的,可以正常自訂尾巴。並且,我們可以自訂一個話題, 這樣,使用《微博小尾巴》這個應用所有人發的微博,都會在這裡顯示,也是比較方便的。具體調用方法如下:
webView.webStr = [NSString stringWithFormat:@"http://widget.weibo.com/topics/topic_vote_base.php?tag=來自微博小尾巴&isshowright=0&language=zh_cn&dup=1&antispam=1&isOutTopicSearch=2&border=0&version=base&footbar=0&app_src=%@", appKey];

這裡的webStr 是一個NSStirng字串, 用來儲存對應的URL。 appKey根據選擇的手機型號, 從plist中擷取。webStr傳入後, 繼續調用顯示。
    webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, 320, Screen_height-64)];    request =[NSURLRequest requestWithURL:[NSURL URLWithString:[webStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];    [webView setDelegate:self];    [self.view addSubview: webView];    [webView loadRequest:request];

這樣的話, 就可以通過網頁形式發布微博。 然後顯示你所喜歡的小尾巴了。 很簡單吧。
3. 應用appKey擷取和使用
同樣的, 我也收集了100多個應用程式名稱, 都挺有意思的。擷取方法: 進入微博應用廣場----> 選擇某個應用----->顯示頁面源碼------>搜尋appKey。 即可擷取。


調用方法:
        webView.webStr = [NSString stringWithFormat:@"http://v.t.sina.com.cn/share/share.php?appkey=%@&;content=utf8", appKey];


二。UITableView + UISearchBar 使用
//添加列表    myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 104, 320, Screen_height - 154)];    myTableView.delegate = self;    myTableView.dataSource = self;    //背景顏色    myTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"eyeBackground.jpg"]];    [self.view addSubview:myTableView];        //初始化搜尋列表bar    filteredArr = [[NSMutableArray alloc]init];    searchBarReagion = [[UISearchBar alloc] initWithFrame:CGRectMake(0,64,320,44)];    searchBarReagion.placeholder = @"搜尋";    searchBarReagion.delegate = self;    [self.view addSubview:searchBarReagion];

#pragma mark#pragma mark SearchBar Delegate- (void) searchBarTextDidBeginEditing: (UISearchBar*) searchBar{        [searchBarReagion setShowsCancelButton: YES animated: YES];}- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{        isSearchActiveDM = TRUE;    [filteredArr removeAllObjects];        for (int i=0; i<resultArr.count; i++)    {        NSDictionary *countryDictinary = [resultArr objectAtIndex:i];        NSRange result=[[countryDictinary objectForKey:@"appName"] rangeOfString:searchText options:NSCaseInsensitiveSearch];                if(result.length>0)        {                        [filteredArr addObject:countryDictinary];        }            }        [myTableView reloadData];}- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{    [searchBarReagion resignFirstResponder];    [searchBarReagion setShowsCancelButton: NO animated: YES];}- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar{        isSearchActiveDM = FALSE;    searchBarReagion.text = @"";    [searchBarReagion setShowsCancelButton: NO animated: YES];    [searchBarReagion resignFirstResponder];        [myTableView reloadData];}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    if (isSearchActiveDM)    {        return [filteredArr count];    }    return [resultArr count];}


通過上面的代碼, 可以看出, 其實, UITableView 和 UISearchBar 沒有直接聯絡的。 都實現各自的方法。只是, 在搜尋方塊輸入內容後, 標記為 isSearchActiveDM。 然後在UITableView需要實現的各個方法中, 通過判斷是否處於isSearchActiveDM, 來顯示不同的資料。從而達到動態搜尋的效果。

三。 UITableView分級菜單這裡, 我在code4app中發現了一個不錯的demo。已經被我整合到應用中了。源檔案在NavigationStackResource這個檔案夾中。調用方法:
    //Initialize the controller data    NSString* plistPath = [[NSBundle mainBundle] pathForResource: @"NavStackControllerData"                                                          ofType: @"plist"];    // Build the array from the plist    self.jsonDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];        //customizing..    [self setHeaderLabelFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:20.0f]];    [self setHeaderLabelColor:[UIColor blackColor]];    [self setHeaderBackGroundColor:[UIColor whiteColor]];        [self setSelectedHeaderLabelFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0f]];    [self setSelectedHeaderLabelColor:[UIColor blackColor]];    [self setSelectedHeaderBackGroundColor:[UIColor whiteColor]];        [self setHeaderSeparatorColor:[UIColor lightGrayColor]];


選擇各個cell回應程式法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    appKey = [[[[self.jsonDictionary objectForKey:self.clickedCountryName]objectForKey:@"subheadingArr"]objectAtIndex:indexPath.row]objectForKey:@"subheadingKey"];    appName = [[[[self.jsonDictionary objectForKey:self.clickedCountryName]objectForKey:@"subheadingArr"]objectAtIndex:indexPath.row]objectForKey:@"subheadingName"];        [self performSegueWithIdentifier:@"phonePushToWeb" sender:self];}



四。有米廣告的植入
1. 註冊應用,申請ID

1)請登陸到 http://www.youmi.net/register 註冊一個開發人員帳號

2)點擊建立應用進行新應用建立。

3)查看應用詳情,擷取發布ID和應用密鑰,在後續初始化中使用。(注意:一個appid只能嚴格對應一個bundle id。如果有特殊需要得聯絡客服 )

2. 下載YouMiSDK iOS 壓縮包

你下載的壓縮包解壓後包含了下面幾個檔案:


doc檔案夾中的doc.html為中文教程,doc_en.html是英文教程。

lib檔案夾就是要添加到你的工程的檔案夾,裡麵包含了libYouMi.a靜態檔案和標頭檔。

samples檔案夾YouMiSDK的程式例子。

3. 往工程匯入標頭檔, 靜態庫檔案

積分牆必須的標頭檔為

  • YouMiConfig.h

  • YouMiWall.h

  • YouMiWallAppModel.h

  • YouMiPointsManager.h (用於查詢積分)

靜態庫檔案為

  • libYouMi.a
4. 為工程添加系統內建的Frameworks
  • Security.framework
  • SystemConfiguration.framework
  • CFNetwork.framework
  • QuartzCore.framework
  • libsqlite3.dylib
  • StoreKit.framework 這個framework要改為Optional,其他都為Required
5. 到AppDelegate.m檔案中初始化YouMiSDK
  • 1)在AppDelegate.m檔案中添加下面這個語句
#import "YouMiConfig.h"
  • 2) 在AppDelegate.m自動產生的
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
的函數裡面添加下面代碼
[YouMiConfig setUserID:id_you_define]; // [可選] 例如開發人員的應用是有登入功能的,則可以使用登入後的使用者帳號來替代有米為每台機器提供的標識(有米會為每台裝置產生的唯一識別碼)。[YouMiConfig setUseInAppStore:YES];  // [可選]開啟內建appStore,詳細請看YouMiSDK常見問題集[YouMiConfig launchWithAppID:@"[Your AppID]" appSecret:@"[Your AppSecret]"]; 

注意替換:Your AppID和Your AppSecret為你的appidappSecret

本文檔的程式碼片段在SDK相應的標頭檔中都有比較詳細的介紹,對於本文檔的代碼有什麼疑問,請查看標頭檔

  • 3)設定顯示全屏廣告(如積分牆)的全屏UIWindow(可選,推薦設定)

對於使用UIKit編寫的APP可以在application:didFinishLaunchingWithOptions:中的[self.window makeKeyAndVisible]之後設定:

[self.window makeKeyAndVisible];// 設定顯示全屏廣告的window   [YouMiConfig setFullScreenWindow:self.window];


這裡, 我的demo裡面只用到了簡單的 廣告條, 至於其他的積分牆什麼的,需要的可以自己參考文檔。
調用廣告條在需要用到廣告條的地方建立廣告條並添加
// 建立廣告條adView = [[YouMiView alloc] initWithContentSizeIdentifier:YouMiBannerContentSizeIdentifier320x50 delegate:nil];//可以設定委託[可選]adView.delegate = self;//設定文字廣告的屬性[可選]adView.indicateTranslucency = YES;adView.indicateRounded = NO;//添加對應的關鍵詞 [可選][adView addKeyword:@"女性"];// 開始請求廣告[adView start];// 把廣告條添加到特定的view中 [例如][self.view addSubview:adView];


新浪微博小尾巴顯示問題

我的也是啊 最近在完善 再等等吧
 
新浪微博小尾巴

微部落格戶端早就取消了尾巴了,想要尾巴去一些論壇,比如機鋒,下一個修改過的微部落格戶端,直接帶尾巴的,採納哦!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.