ASIHttpRequest and ARC

1,074 views
Skip to first unread message

eric_marsh

unread,
Nov 7, 2011, 5:38:56 PM11/7/11
to ASIHTTPRequest
Hi Folks,

I get that Ben doesn't want to support ASIHttpRequest any more. I
can't say that I blame him - having people give you crap for something
that you donated to the community sucks. But on the other hand it's
out there and in many different projects and needs to be supported.

I do contract development work and I'm working on a very large project
that uses ASIHttpRequest. After getting used to it I integrated it
into a project of my own. Right now I'm trying to convert the
commercial project to iOS5 and ARC. I didn't want to convert
ASIHttpRequest because I didn't want to diverge from the common code
base but it looks like I don't have a whole lot of choice. The
customer wants iOS5 and they don't want to spend a lot of money moving
to a new library.

So what about breaking ASIHttpRequest off to a new branch and moving
forward? I don't want to make this thing my life either but if I can
get it working I'm happy to give my changes to the community.

Eric

Joseph Heenan

unread,
Nov 8, 2011, 4:41:08 AM11/8/11
to asihttp...@googlegroups.com
Hi Eric,

ASIHTTPRequest already works fine on iOS5, I'm not sure who is spreading
the rumour that it doesn't.

ARC is a different matter - but you don't *have* to use ARC on iOS5.

Someone (I forgot who, sorry) already has commit access to the official
ASIHTTPRequest repository, so if you have changes to be merged I believe
you just send github pull requests like normal - though I guess if
you're talking about ARC support then that will probably have to be a
separate branch.

Cheers,

Joseph

Marsh Eric

unread,
Nov 8, 2011, 7:15:43 AM11/8/11
to asihttp...@googlegroups.com
I tried disabling ARC and it wouldn't work for me. I don't want to have to port ASIHttpRequest to ARC but it seems like the only way. If there is another I'd like instructions on how to do so.

> --
> You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
> To post to this group, send email to asihttp...@googlegroups.com.
> To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.
>

Joseph Heenan

unread,
Nov 8, 2011, 7:42:31 AM11/8/11
to asihttp...@googlegroups.com
Well at least one way is to disable ARC for the project (this is the
default for projects that were created prior to iOS5) - the option is:

CLANG_ENABLE_OBJC_ARC = NO

This is found in the target 'Build settings' tab, labelled 'Objective-C
Automatic Reference Counting'.

This is working just fine for me.

Joseph

Marsh Eric

unread,
Nov 8, 2011, 8:23:02 AM11/8/11
to asihttp...@googlegroups.com
But I need ARC for the rest of the project. I tried using the flags to turn ARC off on a file by file basis and it simply didn't work. I don't know why. But I have to move forward so right now I'm working on converting ASIHttpRequest to ARC.

Joseph Heenan

unread,
Nov 8, 2011, 8:48:40 AM11/8/11
to asihttp...@googlegroups.com
On 08/11/2011 13:23, Marsh Eric wrote:
> But I need ARC for the rest of the project. I tried using the flags to turn ARC off on a file by file basis and it simply didn't work. I don't know why. But I have to move forward so right now I'm working on converting ASIHttpRequest to ARC.
>

This is perhaps getting off topic now, but I'm curious: Why do you need ARC?


Joseph

Chris Davis

unread,
Nov 8, 2011, 8:58:23 AM11/8/11
to asihttp...@googlegroups.com
Because ARC is more efficient, less code, easier to maintain, less
prone to crash, need I go on? Eric...please make an ARC version as I
would be extremely grateful!!!

Chris Davis

Sent from my iPhone

Marsh Eric

unread,
Nov 8, 2011, 8:59:31 AM11/8/11
to asihttp...@googlegroups.com
I've been given a very complex project with 125+ source files. It's going down occasionally because of issues with improper memory releasing and I've already chewed up a lot of hours trying to nail this thing down. Rather than burning through more hours trying to find an irritate and inconsistent bug I'm converting to ARC in the hope that it will sort thing out. Essentially I'm trying to make the best decision for my customer.

Marsh Eric

unread,
Nov 8, 2011, 9:20:38 AM11/8/11
to asihttp...@googlegroups.com
I'm happy to share what I do when I've done the work. Seems like it may be a good idea to just branch the code. There are so many differences it would be very difficult to use pragmas.

Bart Whiteley

unread,
Nov 8, 2011, 11:11:58 AM11/8/11
to asihttp...@googlegroups.com
I've got a project about the same size as the one you describe that I
recently converted to ARC. It uses ASIHTTPRequest. The conversion
process was completed within one work day. I'll share my experience
with the conversion in the hopes that it might benefit others on the
list.

I followed these steps:
http://www.daveoncode.com/2011/10/24/migration-to-arc-automatic-reference-counting-using-xcode-4-2-refactor/

Note that when you "select targets to convert", you can expand the
project and uncheck specific files. Uncheck all of the ASI* files.
Then run the precheck, and fix the problems. Then start the process
over again and repeat until there are no problems. I noticed that
sometimes Xcode didn't remember that I had unchecked the ASI* files in
the previous iteration. I had to make sure they were unchecked each
time.

Once the precheck works, run the conversion and examine the code. I
had to make a few adjustments to the generated code. If you are happy
with the changes, save them and then build. At this point I was
presented with a new set of errors/warnings, different from those
fixed during precheck. Once I worked through those issues, the
project built and ran properly on iOS5. It didn't work correctly on
iOS4, but after hunting down another bug it now runs correctly on both
iOS4 and iOS5. There do seem to be some behavioral differences with
ARC on iOS4 and iOS5. Some bugs only manifest themselves on one or
the other.

Note that it is still pretty easy to end up with retain cycles that
the compiler/analyzer won't find. You have to take care to use "weak"
or "unsafe_unretained" properly to break such cycles. In the URL
above, the author states that he replaced the generated
"unsafe_unretained" instances with "strong". Don't do that unless you
really understand what's going on.

In addition to the direct benefit that I now have ARC code, the
conversion process revealed some problems and helped me improve the
code. In a later email you state that you're hoping that converting
to ARC will help sort out some of the problems. I found that was
indeed the case.

Hope this helps. Good luck.

Joseph Heenan

unread,
Nov 8, 2011, 1:44:42 PM11/8/11
to asihttp...@googlegroups.com
Hi Bart,

Thanks for sharing that; sounds very interesting!

Joseph

Joseph Heenan

unread,
Nov 8, 2011, 1:52:47 PM11/8/11
to asihttp...@googlegroups.com
Ouch - not a good situation to be in :-(

I can certainly understand your motivation - good luck, and let us know
how you get on.

(If you get stuck and decide to go back to trying to fix the memory
handling instead, drop me an email off list as I may be able to help -
it's the sort of project my company has successfully taken on before,
big complex projects with difficult problems are very much our thing.)

Cheers,

Joseph

Marsh Eric

unread,
Nov 8, 2011, 1:56:58 PM11/8/11
to asihttp...@googlegroups.com
Thanks - I have it building and running - can't say if all the ARC stuff is working right yet though.

Lazereth

unread,
Nov 9, 2011, 9:44:06 AM11/9/11
to ASIHTTPRequest
Hey all - i wrote a ARC compliant HTTPRequest class that uses the
default Apple functionality but with the same structure as ASI.
Ive hosted it at github if interested its....

https://github.com/imathome/ARCHTTPRequest

Its by far not a complete solution but will resolve a number of
situations for most users. Hope its of some use.

Regards,
Samuel (Lazereth)

Kurry

unread,
Nov 9, 2011, 2:55:14 PM11/9/11
to ASIHTTPRequest
Thank you so much! This is exactly what I needed.

Samuel Colak

unread,
Nov 11, 2011, 4:12:09 AM11/11/11
to asihttp...@googlegroups.com
No problem - glad this helps. Ill track the requests as they come in and modify the
library as appropriate. The principle behind this is more to keep things simple, fast and
compliant to ARC.

Viju Varghese

unread,
Nov 14, 2011, 9:18:16 PM11/14/11
to asihttp...@googlegroups.com
Experts, I am using ASIHTTPRequest to access a webservice that takes slightly longer time. I set the setPersistentTimeoutSeconds to 300.
I still get the error "The request timed out".  But when run the same request in browser, it is not takes 20-30 seconds only to return the response.
Any ideas how to fix the issue?
Thanks in advance.

eric_marsh

unread,
Nov 15, 2011, 5:31:38 PM11/15/11
to ASIHTTPRequest
Bart, thanks for the tips. At this point things are looking pretty
good.

Samuel Colak

unread,
Nov 15, 2011, 1:48:29 AM11/15/11
to asihttp...@googlegroups.com
Viju,

this is one reason i advise to switch to the new implementation on GitHub for this kind of matter. Simply implement the delegate function
and deal with authentication as you like. If you need some assistance, just give me a shout and ill write a short example on how to achieve
what you are trying to do.

Regards,
Samuel (Lazereth)

Reply all
Reply to author
Forward
0 new messages