IOS上的几个类库:MBProgressHUD、ASIHttpRequest、JSON Framework和Flurry

 

每个库的简单介绍请参见:10款IOS高效开发必备的Objective-C类库(http://mobile.csdn.net/a/20110317/294018.html

    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对象可以自由的在这三种模式之间变换,这样就可以在不同的阶段有不同的呈现形式。

          当然还有很多的属性可以设置,以达到不同的目的,具体参见源代码。简单用法参见:http://auauau.iteye.com/blog/575415或者http://blog.csdn.net/tangaowen/article/details/6528136

    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 logError to 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.

(以上flurry的英文文字及代码均来自flurry网站)。

转载:http://blog.csdn.net/xiaoguan2008/article/details/6732814

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值