0

I'm working on the script in objective-c. I created a "Command Line Tool" in xcode and I want to request a JSON web service.

In my previous iPhone apps I use to import ASIHTTPRequest framework. Unfortunetly this framework use UIKit library.

I don't want to import this library and all these dependencies.

Do you know a good framework or library that I can use in my Command Line Tool application ?

Thanks.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Maxime Capelle
  • 887
  • 7
  • 16

2 Answers2

4

ASIHTTPRequest shouldn't require UIKit. You should be able to remove that if it's there. You can't import UIKit into a Mac app anyway.

The ASI framework has been discontinued, though. You may want to look at other options such as MKNetworkKit and AFNetworking. Both should work fine in a commandline app.


EDIT: Don't forget that most frameworks like this will require a run loop. The typical way to manage that in a commandline app looks like this (from NSRunLoop docs):

BOOL shouldKeepRunning = YES;        // global
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);

This is an infinite loop until something sets shouldKeepRunning.

You can also use NSApplication as shown in Run NSRunLoop in a Cocoa command-line program.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thanks for the advice. So I tried AFNetworking. I installed it successfully in my project after removing files using NSImage that cause a compilation error. Unfortunetly for the moment I can't get my web service request working. I followed the document example withouh success. But no log is written (success ou failure). So I don't know why it doesn't work. – Maxime Capelle Feb 14 '12 at 18:36
  • Sorry but I don't know how to put my code here properly. All the code is on the same line so it's unreadable. – Maxime Capelle Feb 14 '12 at 18:56
  • 1
    ace, I've been looking for this run loop stuff – Adam Waite May 03 '13 at 12:35
  • calling dispatch_main is often a better way to run the infinite loop. – Puneet Sharma Jan 20 '17 at 03:17
0

You can use ASIHTTPRequest in a command line tool.

For an example feel free to look at my pinch-objc project available at github. See the zipcommander project.

https://github.com/epatel/pinch-objc

epatel
  • 45,805
  • 17
  • 110
  • 144