标签:开发者   程序员   微博小尾巴   自定义微博小尾巴   
自从王思聪发布了那条小尾巴是iphone6的微博之后,引起了无数人的跟风,大家争先恐后的把自己的小尾巴改成iphone6。但是好景不长,新浪就把这个方法给和谐了。
被“无情”和谐掉的小尾巴是通过“网页发布窗”来实现的,可手动设置app_url(也就是每个型号手机对应的key),用这种方法可以自行修改微博的小尾巴。而本文我来分享下基于iOS平台APP实现自定义修改微博小尾巴。





建议先下载源码(点击此处下载)
注:此源码是基于iOS的,但实现方法、相应接口和数据都是通用的,接口是新浪的,但是什么时候会被和谐掉,这个小编可不敢说,总之可以先用着。
源码内容包括~
*微博接口分析
* UITableView + UISearchBar 使用
*UITableView分级菜单
*有米广告嵌入
微博接口分析~
微博尾巴可以分为两大类:手机型号和应用名称。
手机型号:我们正常发微博的时候,如果是手机,会根据设备信息,自动显示对应尾巴。新浪会为每个设备分配一个app_url,这个是唯一的。
应用名称:每一个在微博开放平台注册过的应用都有独立的分享链接,会带上对应的尾巴。而区分各个应用的就是对应的appKey。
1、获取各个手机型号的app_url
小编这是罗列了几个比较常用的(当然不能少了iphone的了,装逼必备嘛~),文件格式是.plist. iOS便可以直接打开,但是其他系统上,需要自己去读,它的格式是XML。
获取方法:A、百度收集B、右键微博,查看链接

2、手机型号调用方法
之前使用过调用发布窗,但是已经被和谐掉了,本次尝试“话题窗”,自定义尾巴。这样,使用《微博小尾巴》这个应用的所有人发的微博,都会在这里显示,也是比较方便的。
调用方法如下:
| 1 | webView.webStr = [NSString stringWithFormat:@"http: | 
 
| 2 | &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传入后, 继续调用显示。
| 1 | webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, 320, Screen_height-64)];   | 
 
| 2 | request =[NSURLRequest requestWithURL:[NSURL URLWithString:[webStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];   | 
 
| 3 | [webView setDelegate:self];   | 
 
| 4 | [self.view addSubview: webView];   | 
 
| 5 | [webView loadRequest:request]; | 
 
 
 
这样便可以通过网页形式发布微博,然后显示你喜欢的小尾巴了~是不是很简单~
3、应用appKey获取和使用
获取方法:
进入微博应用广场----> 选择某个应用----->显示页面源码------>搜索appKey。

调用方法:
UITableView + UISearchBar 使用~
| 02 |     myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 104, 320, Screen_height - 154)];   | 
 
| 03 |     myTableView.delegate = self;   | 
 
| 04 |     myTableView.dataSource = self;   | 
 
| 06 |     myTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"eyeBackground.jpg"]];   | 
 
| 07 |     [self.view addSubview:myTableView];   | 
 
| 10 |     filteredArr = [[NSMutableArray alloc]init];   | 
 
| 11 |     searchBarReagion = [[UISearchBar alloc] initWithFrame:CGRectMake(0,64,320,44)];   | 
 
| 12 |     searchBarReagion.placeholder = @"搜索";   | 
 
| 13 |     searchBarReagion.delegate = self;   | 
 
| 14 |     [self.view addSubview:searchBarReagion]; | 
 
 
 
| 02 | #pragma mark SearchBar Delegate   | 
 
| 04 | - (void) searchBarTextDidBeginEditing: (UISearchBar*) searchBar   | 
 
| 07 |     [searchBarReagion setShowsCancelButton: YES animated: YES];   | 
 
| 10 | - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText   | 
 
| 13 |     isSearchActiveDM = TRUE;   | 
 
| 14 |     [filteredArr removeAllObjects];   | 
 
| 19 |             [filteredArr addObject:countryDictinary];   | 
 
| 24 |     [myTableView reloadData];   | 
 
| 27 | - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar   | 
 
| 29 |     [searchBarReagion resignFirstResponder];   | 
 
| 30 |     [searchBarReagion setShowsCancelButton: NO animated: YES];   | 
 
| 33 | - (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar   | 
 
| 36 |     isSearchActiveDM = FALSE;   | 
 
| 37 |     searchBarReagion.text = @"";   | 
 
| 38 |     [searchBarReagion setShowsCancelButton: NO animated: YES];   | 
 
| 39 |     [searchBarReagion resignFirstResponder];   | 
 
| 41 |     [myTableView reloadData];   | 
 
 
 
| 1 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   | 
 
| 5 |         return[filteredArr count];   | 
 
| 7 |     return[resultArr count];   | 
 
 
 
通过以上代码可以发现,UITableView 和 UISearchBar 是没有直接联系的,都实现自己的方法。只是在搜索框输入内容后,标记为 isSearchActiveDM,然后在UITableView实现的各个方法中, 通过判断是否处于isSearchActiveDM, 来显示不同的数据,从而达到动态搜索的效果。
UITableView分级菜单~
小编在code4app发现一个不错的DEMO并将其整合到了应用中,源文件在NavigationStackResource文件夹中,调用方法如下:
| 02 | NSString* plistPath = [[NSBundle mainBundle] pathForResource: @"NavStackControllerData" | 
 
| 05 | self.jsonDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];   | 
 
| 08 | [self setHeaderLabelFont:[UIFont fontWithName:@"HelveticaNeue-Light"size:20.0f]];   | 
 
| 09 | [self setHeaderLabelColor:[UIColor blackColor]];   | 
 
| 10 | [self setHeaderBackGroundColor:[UIColor whiteColor]];   | 
 
| 12 | [self setSelectedHeaderLabelFont:[UIFont fontWithName:@"HelveticaNeue-Bold"size:20.0f]];   | 
 
| 13 | [self setSelectedHeaderLabelColor:[UIColor blackColor]];   | 
 
| 14 | [self setSelectedHeaderBackGroundColor:[UIColor whiteColor]];   | 
 
| 16 | [self setHeaderSeparatorColor:[UIColor lightGrayColor]]; | 
 
 
 
选择各个cell响应方法:
| 1 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath   | 
 
| 3 |     appKey = [[[[self.jsonDictionary objectForKey:self.clickedCountryName]objectForKey:@"subheadingArr"]objectAtIndex:indexPath.row]objectForKey:@"subheadingKey"];   | 
 
| 4 |     appName = [[[[self.jsonDictionary objectForKey:self.clickedCountryName]objectForKey:@"subheadingArr"]objectAtIndex:indexPath.row]objectForKey:@"subheadingName"];   | 
 
| 6 |     [self performSegueWithIdentifier:@"phonePushToWeb"sender:self];   | 
 
 
 
有米广告的植入~
1、注册应用,申请id
可登录有米官网注册一个开发者账号,获取发布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文件中添加以下语句
| 1 | #import "YouMiConfig.h" | 
 
 
 
(2)在AppDelegate.m自动生成的
| 1 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | 
 
 
 
的函数中添加以下代码:
| 1 | [YouMiConfig setUserID:id_you_define];  | 
 
| 2 | [YouMiConfig setUseInAppStore:YES];   | 
 
| 3 | [YouMiConfig launchWithAppID:@"[Your AppID]"appSecret:@"[Your AppSecret]"]; | 
 
 
 
注1:替换“Your AppID”和“Your AppSecret“为你的appid和appSecret。
注2:本文档的代码片段在SDK相应的头文件中都有比较详细的介绍,对于本文档的代码有什么疑问,可查看头文件。
(3)设置显示全屏广告(如积分墙)的全屏UIWindow(此处可选,推荐设置)
对于使用UIKit编写的APP可以在application:didFinishLaunchingWithOptions:中的[self.window makeKeyAndVisible]之后设置:
| 1 | [self.window makeKeyAndVisible]; | 
 
| 3 | [YouMiConfig setFullScreenWindow:self.window]; | 
 
 
 
这里,小编只是说明了简单的广告条。
调用广告条~
在需要用到广告条的地方创建广告条并添加
| 02 | adView = [[YouMiView alloc] initWithContentSizeIdentifier:YouMiBannerContentSizeIdentifier320x50 delegate:nil]; | 
| 05 | adView.delegate = self; | 
| 07 | adView.indicateTranslucency = YES; | 
| 08 | adView.indicateRounded = NO; | 
| 10 | [adView addKeyword:@"女性"]; | 
| 16 | [self.view addSubview:adView]; | 
 
 
基于iOS平台的app自定义微博小尾巴就讲解到此,想不想土豪一把?想不想让受人膜拜?想的话就自己动手试试吧,让你的微博小尾巴闪亮亮!!!
码农福利,自定义微博小尾巴,闪瞎他们的双眼
标签:开发者   程序员   微博小尾巴   自定义微博小尾巴   
原文地址:http://blog.csdn.net/c1782746138/article/details/39547901