views:

295

answers:

5

I have a warning on objective c for iphone it says "implicit declaration of function 'sleep'"

All I have is a sleep(1); for the splash in the applicationDidFinishLaunching

I didn't have this problem in prior versions of the sdk

I know is just a warning, but I had problems before with apple for not having 100% success

Thanks for everything :D

A: 

You may just declare it's prototype in the file where you are using it:

unsigned int sleep( unsigned int seconds );

Or simply include <unistd.h>

Macmade
if he has to declare the prototype, he's missing a header. This is a band-aid.
Joshua Weinberg
You should *never* declare a prototype to enable the use of the function. At best, it means you haven't included the right header. At worst, it indicates use of private interfaces that may cause crashes or rejections. Or it is a good way to introduce a bug if you get the prototype wrong.
bbum
it doesn't crash, it works fine ;) thanks any way
Saikios
Wow...just....wow...
Joshua Weinberg
@Joshua Weinberg: well look at it this way, if you are like me, apps that put up unnecessary splash screens don't stay installed for long so this shouldn't be overly bothersome.
JeremyP
@Saikios: the correct header for sleep(3) is unistd.h. http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man3/sleep.3.html
JeremyP
I would never install this app, but, if pepople like girls not wearing a lot of clothes they are going to wait 1 second :P, and probably more too :P
Saikios
+6  A: 

Make sure you're including the right headers. <Foundation/Foundation.h> has all the stuff you should need, if you're not in Obj-C code though, include <unistd.h> and everything should be happy.

Joshua Weinberg
+2  A: 

How about using

[NSThread sleepForTimeInterval:0.1];

or something instead?

Woody
A: 

Why are you sleeping? That is the worst possible place to sleep; if you application does not return from applicationDidFinishLaunching, it will be killed. And you are making that take a second longer!!

Instead, in applicationDidFinishLaunching put up the same image, then dismiss it after a delay. That way your application can continue to initialize even though the splash screen is still displayed...

Kendall Helmstetter Gelner
It was on a manual :(
Saikios
A: 

Here's how to fix your problem.

If you have:

sleep(1);

change it to

// sleep(1);

If you really must force the user to watch your advertising instead of getting on with using your app, which is what they really want to do, display your splash screen then use an NSTimer event to remove it. That means that you can do useful stuff while it's there.

JeremyP