IOS上的几个类库:MBProgressHUD、ASIHttpRequest、JSON Framework和Flurry
2013-07-10 13:04
435 查看
上述的四个类库我都试验过,确实还不错。每个库的简单介绍请参见:10款IOS高效开发必备的Objective-C类库(http://www.csdn.net/article/2011-03-17/294018)。
1、MBProgressHUD:https://github.com/jdg/MBProgressHUD。
HUD = [[MBProgressHUD alloc]initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate =self;
HUD.labelText =@"Loading";
HUD.detailsLabelText =@"updating data";
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
以上是一个最简单的实现方法,MBProgressHUD对象可以设置委托,委托方法为hudWasHidden,可以在此方法中remove掉之前创建的变量HUD。
HUD.mode =MBProgressHUDModeDeterminate;设置MBProgressHUD的模式,MBProgressHUD有三种模式,分别为:
MBProgressHUDModeIndeterminate,(UIActivityIndicatorView,default)
MBProgressHUDModeDeterminate,(MBRoundProgressView)
MBProgressHUDModeCustomView
在MBProgressHUDModeDeterminate模式下,可以设置HUD.progress来控制进度。
在MBProgressHUDModeCustomView模式下,可以设置HUD.customView来显示图片,图片大小为37*37时显示效果最好。
MBProgressHUD对象可以自由的在这三种模式之间变换,这样就可以在不同的阶段有不同的呈现形式。
当然还有很多的属性可以设置,以达到不同的目的,具体参见源代码。简单用法参见:/article/4437765.html或者/article/2936108.html。
2、ASIHttpRequest:http://allseeing-i.com/ASIHTTPRequest/或者https://github.com/pokeb/asi-http-request/tree
最简单的连接方式:
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]];//此处貌似必须加http
[self setRequest:[ASIHTTPRequest requestWithURL:url]];
[request addRequestHeader:@"User-Agent"value:@"ASIHTTPRequest"];
[request startSynchronous];
//其中request为ASIHTTPRequest对象
ASIHTTPRequest中几个比较有用的参数:
url:request请求中的url
requestMethod:提交的方式,默认为GET
postBody:以POST方式提交时所带的数据
responseHeaders:返回的response的Headers
error:错误,可参见ASINetworkErrorType(在ASIHTTPRequest类中)
responseString:这是一个方法,获得返回的结果
。。。。。。。。
request可以设置代理:[request setDelegate:***];
还可以设置进度条:[request setDownloadProgressDelegate:***];
使用ASINetworkQueue可以实现多线程的方式进行数据的获取。使用方法与NSOperationQueue类似.
使用ASIFormDataRequest进行POST方式提交,使用setPostValue增加post的值,当然你也可以用addPostValue。
3、JSON Framework:参见我的文章(http://blog.csdn.net/xiaoguan2008/article/details/6732683)
4、Flurry:一个很强大的统计工具,http://www.flurry.com/product/analytics/index.html
使用起来也很简单,首先在Flurry网站上进行注册(https://dev.flurry.com/secure/login.do),成功后new
application,此时会有相应的sdk给你下载。下载后直接加入到你的工程中即可。接下来是使用:
In your
Import FlurryAnalytics and inside "applicationDidFinishLaunching:" add: [FlurryAnalytics startSession:@"PTVUJQUHI6MUMJP22GQK"];
You can use the following methods to report additional data.
Tracking User Behavior
An example NSDictionary to use with this method could be:
Tracking Application Errors
Use this to log exceptions and/or errors that occur in your app. Flurry will report the first 10 errors that occur in each session.
我们还可以使用flurry记录程序意外的crash信息,如下:
We recommend adding an uncaught exception listener to your application (if you don't already have one) and
use
listener is easy; you just need to create a function that looks like the following:
You then need to register this function as an uncaught exception listener as follows:
Note that you can name the function whatever you'd like and record whatever error information you'd like in the error name and event fields.
1、MBProgressHUD:https://github.com/jdg/MBProgressHUD。
HUD = [[MBProgressHUD alloc]initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate =self;
HUD.labelText =@"Loading";
HUD.detailsLabelText =@"updating data";
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
以上是一个最简单的实现方法,MBProgressHUD对象可以设置委托,委托方法为hudWasHidden,可以在此方法中remove掉之前创建的变量HUD。
HUD.mode =MBProgressHUDModeDeterminate;设置MBProgressHUD的模式,MBProgressHUD有三种模式,分别为:
MBProgressHUDModeIndeterminate,(UIActivityIndicatorView,default)
MBProgressHUDModeDeterminate,(MBRoundProgressView)
MBProgressHUDModeCustomView
在MBProgressHUDModeDeterminate模式下,可以设置HUD.progress来控制进度。
在MBProgressHUDModeCustomView模式下,可以设置HUD.customView来显示图片,图片大小为37*37时显示效果最好。
MBProgressHUD对象可以自由的在这三种模式之间变换,这样就可以在不同的阶段有不同的呈现形式。
当然还有很多的属性可以设置,以达到不同的目的,具体参见源代码。简单用法参见:/article/4437765.html或者/article/2936108.html。
2、ASIHttpRequest:http://allseeing-i.com/ASIHTTPRequest/或者https://github.com/pokeb/asi-http-request/tree
最简单的连接方式:
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]];//此处貌似必须加http
[self setRequest:[ASIHTTPRequest requestWithURL:url]];
[request addRequestHeader:@"User-Agent"value:@"ASIHTTPRequest"];
[request startSynchronous];
//其中request为ASIHTTPRequest对象
ASIHTTPRequest中几个比较有用的参数:
url:request请求中的url
requestMethod:提交的方式,默认为GET
postBody:以POST方式提交时所带的数据
responseHeaders:返回的response的Headers
error:错误,可参见ASINetworkErrorType(在ASIHTTPRequest类中)
responseString:这是一个方法,获得返回的结果
。。。。。。。。
request可以设置代理:[request setDelegate:***];
还可以设置进度条:[request setDownloadProgressDelegate:***];
使用ASINetworkQueue可以实现多线程的方式进行数据的获取。使用方法与NSOperationQueue类似.
使用ASIFormDataRequest进行POST方式提交,使用setPostValue增加post的值,当然你也可以用addPostValue。
3、JSON Framework:参见我的文章(http://blog.csdn.net/xiaoguan2008/article/details/6732683)
4、Flurry:一个很强大的统计工具,http://www.flurry.com/product/analytics/index.html
使用起来也很简单,首先在Flurry网站上进行注册(https://dev.flurry.com/secure/login.do),成功后new
application,此时会有相应的sdk给你下载。下载后直接加入到你的工程中即可。接下来是使用:
In your
Application Delegate:
Import FlurryAnalytics and inside "applicationDidFinishLaunching:" add: [FlurryAnalytics startSession:@"PTVUJQUHI6MUMJP22GQK"];
#import "FlurryAnalytics.h"
- (void)applicationDidFinishLaunching:(UIApplication *)application { [FlurryAnalytics startSession:@"PTVUJQUHI6MUMJP22GQK"];//每个应用程序的唯一标示,flurry生成的。 //your code }
You can use the following methods to report additional data.
Tracking User Behavior
[FlurryAnalytics logEvent:@"EVENT_NAME"];
[FlurryAnalytics logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
An example NSDictionary to use with this method could be:
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"your dynamic parameter value", @"your dynamic parameter name", nil];
[FlurryAnalytics logEvent:@"EVENT_NAME" timed:YES];
[FlurryAnalytics logEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary timed:YES];
[FlurryAnalytics endTimedEvent:@"EVENT_NAME" withParameters:YOUR_NSDictionary];
[FlurryAnalytics logAllPageViews:navigationController];
[FlurryAnalytics logPageView];
Tracking Application Errors
[FlurryAnalytics logError:@"ERROR_NAME" message:@"ERROR_MESSAGE" exception:e];
Use this to log exceptions and/or errors that occur in your app. Flurry will report the first 10 errors that occur in each session.
我们还可以使用flurry记录程序意外的crash信息,如下:
We recommend adding an uncaught exception listener to your application (if you don't already have one) and
use
logErrorto record any application crashes. Adding an uncaught exception
listener is easy; you just need to create a function that looks like the following:
void uncaughtExceptionHandler(NSException *exception) { [FlurryAnalytics logError:@"Uncaught" message:@"Crash!" exception:exception]; }
You then need to register this function as an uncaught exception listener as follows:
- (void)applicationDidFinishLaunching:(UIApplication *)application { NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); [FlurryAnalytics startSession:@"PTVUJQUHI6MUMJP22GQK"]; .... }
Note that you can name the function whatever you'd like and record whatever error information you'd like in the error name and event fields.
相关文章推荐
- IOS上的几个类库:MBProgressHUD、ASIHttpRequest、JSON Framework和Flurry
- IOS上的几个类库:MBProgressHUD、ASIHttpRequest、JSON Framework和Flurry
- IOS上的几个类库:MBProgressHUD、ASIHttpRequest、JSON Framework和Flurry
- ASIHttpRequest和json-framework实现json解析(iOS客户端)
- iPhone开发笔记(9)ASIHttpRequest和json-framework实现json解析(iOS客户端)
- ASIHttpRequest和json-framework实现json解析(iOS客户端)
- iPhone开发笔记(9)ASIHttpRequest和json-framework实现json解析(iOS客户端)
- iPhone开发笔记(9)ASIHttpRequest和json-framework实现json解析(iOS客户端)
- iOS代码技巧之ASIHttpRequest类库的使用及Json解析(以解析中国天气网天气预报为例)
- iOS开发-ASIHTTPRequest类库简介和使用说明
- iOS通过ASIHTTPRequest提交JSON数据
- iOS 的 ASIHTTPRequest 类库简介和使用说明
- iOS通过ASIHTTPRequest提交JSON数据
- IOS学习 断点续传简单实现-ASIHTTPRequest类库简介和使用说明
- iOS通过ASIHTTPRequest提交JSON数据
- IOS ASIHTTPRequest类库简介和使用说明
- 详解iOS通过ASIHTTPRequest提交JSON数据
- [IOS] ASIHttpRequest库使用过程中发现的几个小问题
- IOS中使用ASIHTTPRequest类库时出现的问题解决
- iOS总结:ASIHttpRequest类库发送请求(同步请求和异步请求)