Hi I am just starting to develop Iphone apps, it's my first day. And I have to use some code a colleague gave me (he has xcode 4.1 or 4.2) l just to quickly try it out but It doesn't compile and I don't understand why. I have iphone SDK 3.1 and xcode 3.2 (i think). Updating to any other version is out of the question so is there a way I could fix these compilation errors?
I get the following errors in iLikeItAppDelegate.m
#synthesize window=_window;
!synthesized property 'window' must either be named the same as a compatible iva or must
explicitly name an ivar
#synthesize viewController=_viewController;
!kind of similar comment here
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
When I opened the project i tried to compile and it said something about iphoneos not found and the I had it changed to one of the sdks I have and now i get these weird errors. Please anybody help me thanks
EDIT: I managed to replace some staff by other and now I have this class:
#import "iLikeItAppDelegate.h"
#import "iLikeItViewController.h"
#implementation iLikeItAppDelegate
#synthesize window;
#synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//self.window.viewController
//self.window.rootViewController = self.viewController;
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}
- (void)dealloc
{
[window release];
[viewController release];
[super dealloc];
}
#end
but I have another compilation errors now and ones I don't even understand:
"__Block_object_dispose", referenced from:
___destroy_helper_block_1 in iLikeItViewController.o
___destroy_helper_block_3 in iLikeItViewController.o
___destroy_helper_block_4 in iLikeItViewController.o
___destroy_helper_block_2 in iLikeItViewController.o
"__Block_object_assign", referenced from:
___copy_helper_block_1 in iLikeItViewController.o
___copy_helper_block_3 in iLikeItViewController.o
___copy_helper_block_4 in iLikeItViewController.o
___copy_helper_block_2 in iLikeItViewController.o
"__NSConcreteStackBlock", referenced from:
__NSConcreteStackBlock$non_lazy_ptr in iLikeItViewController.o
(maybe you meant: __NSConcreteStackBlock$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
Could anybody help plz I need to learn these basics steps to transform xcode 4 projetcs into 3 because I have snow Leopard and that's the latest version the system lets me install.
rootViewController property is available in iOS 4.0 and later , read here
My advice : get newest SDK
Related
I have built a simple apps that connect to a sqlite database, and the app uses storyboards for UI. On first time, it will throw up a login view. If my authenticate was successful, I change my status in the sqlite database to 1. By default, it is 0. After login, I can use the app.
For example if I kill the app, how can I know my app has been killed? I need to change the status become default again. so whenever I click on the app again, I have to sign in again.
Any idea how to do this? thanks.
Your application delegate implements several methods which handle state changes in your application. From the UIApplication.h header.
- (void)applicationDidFinishLaunching:(UIApplication *)application;
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions NS_AVAILABLE_IOS(6_0);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions NS_AVAILABLE_IOS(3_0);
- (void)applicationDidBecomeActive:(UIApplication *)application;
- (void)applicationWillResignActive:(UIApplication *)application;
- (void)applicationWillTerminate:(UIApplication *)application;
You can implement whichever methods are relevant, in this case the applicationWillTerminate method to change state. Alternatively, always throw up a login view in applicationDidBecomeActive. (This doesn't, however solve the issue updating the database. If the database is local, there's no problem, simply change the database before resigning or terminating. The challenge here would be if your database lives on a server. Although it might bot be an issue, I could see connection timeouts affecting the integrity of the remote values.)
These methods are added to your project automatically in your application delegate, which can be found in the AppDelegate.h & AppDelegate.m files.
For a complete explanation, have a look at the UIApplication Delegate protocol reference.
You can perform close down actions in,
- (void)applicationWillTerminate:(UIApplication *)application
{
// Log out?
}
You can also do the same if your app isn't killed but just gets suspended, such as during an incoming call,
- (void)applicationWillResignActive:(UIApplication *)application
{
// Log out?
}
or,
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Log out?
}
Alternatively, on resume,
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Log in?
}
or,
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Log in?
}
You can't detect if you app was killed, since the process of you app gets killed by the system and no code is called to inform your app that it has been killed.
What you want is to set te some kins of boolean in :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Since this is called if you restart the app after it has been killed.
For the other states seen the answer by Moshe
EDIT
use the delegate methods
such as:
applicationWillResignActive
i want to make my game loading image last longer(Default.png), how?
What you can do is, in your application did finish launching method you can use NSThread to sleep for time interval of 2 sec.
Like this
-(void)applicationDidFinishLaunching
{
[NSThread sleepForTimeInterval:2.0f];
}
But if you want to do some work behind the sense than you can dispatch a custom queue to get the work done using Grand Central Dispatch.
Check the apple documentation on it.
In the Appdelegate :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sleep (3);
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
The sleep (3); means that the loading screen (Default.png) will load/sleep for 3 seconds.
So actually you just have to put the seconds you want in the ().
For example 5 sec : sleep(5);
How can I diagnose this error?
Application Specific Information:
MyApp failed to launch in time
Elapsed total CPU time (seconds): 4913.443 (user 3868.270, system 1045.173), 56% CPU
Elapsed application CPU time (seconds): 0.010, 0% CPU
Backtrace not available
Unknown thread crashed with unknown flavor: 5, state_count: 1
Binary Images:
0x2fe00000 - 0x2fe26fff dyld armv7 <a11905c8ef7906bf4b8910fc551f9dbb> /usr/lib/dyld
Here is my didFinishLaunching method:
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
{
NSLog(#"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
// Override point for customization after application launch.
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
//Check for connectivity
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifer];
[self updateInterfaceWithReachability: internetReach];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
You're probably doing a lot of setup work in your AppDelegate's application:didFinishLaunching method.
You should make sure this function exits as soon as possible. Any setup-work that takes time (network access for example) should be done asynchronously in your application. While this is going on, you can show a spinner to indicate to the user that the application is loading.
In order to add so information to Philippe Leybaert response.
If the application take to much time to start the main thread will be kill so the application will crash.
When you're using the simulator, it will not crash.
When you are using your iphone connected to xcode it will not crash.
When you send it for App Store it might be accepted if the Apple tester is using a fast iPhone
When your users on slow like iPhone 3S will crash
A way to test this issu before submitting is to deploy to testflight or with adhoc and install it on the slower device you want to support.
Just try to divide your application:didFinishLaunchingWithOptions: method code to different function calls and make those calls in background using the threads other then main and make sure that application:didFinishLaunchingWithOptions: method returns as soon as possible
you can use
dispatch_async(dispatch_get_main_queue(), ^{
//put your code
}
I have resolved the issue using this code !
is it any possibilities to invoke/call iphone application from different application, if so means, whats the snippet for that..
This is a specific example, but, if you setup a protocol handler, when a url is loaded by Safari that it can't handle (yourappProtocol://) it will fire off your application to handle it.
You need to add runtime config to your Info.plist.
And then implement the delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
[viewController handleURL:url];
return YES;
}
Read more info here: http://www.mobileorchard.com/apple-approved-iphone-inter-process-communication/
And here: http://blog.innerfence.com/2009/01/05/2-way-app-integration-on-the-iphone-how-it-works/
Note that the protocol handler for your application must be unique - if more than one application installed on an iPhone respond to the same handler, there is no way of knowing which app will launch.
i.e.
tweet://... - bad.
mySuperTwitterApp://... - good.
I'm trying to handle phone calls and standby and things of that nature. I added the function
- (void)applicationWillResignActive:(UIApplication *)application
and
- (void)applicationDidBecomeActive:(UIApplication *)application
to my UIApplicationDelegate. When coming out of standby, "applicationDidBecomeActive" always gets called. However the issue is "applicationWillResignActive" never gets called.
I was wondering if anyone has run into this issue and whether or not anyone found a reason.
EDIT
More info, I discovered that my engine's update loop that gets run from applicationDidFinishLaunching was causing me to miss the message. I call
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, .002, FALSE) == kCFRunLoopRunHandledSource);
to catch all iphone messages but it doesn't seem to catch the resignActive message before becoming inactive.
Attempting to fork a thread for my update loop is causing weird crash bugs. Anyone have any quick fix suggestions?
Its getting called in iOS 4.0 , when the Home button is hit.
The following delegate methods are called when the Home button is hit in iOS 4.0
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(#"Application Did Resign Active");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(#"Application Did Enter Background");
}
And when you double tap the home button and again relaunch the App , the following delegate methods are called .
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"Application Will Enter Foreground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(#"Application Did Become Active");
}
I don't think
- (void)applicationWillResignActive:(UIApplication *)application
is called when a phone call is received. I think the OS waits for the user to either answer or declines the phone call. If it i declined, then the app says alive and
- (void)applicationDidBecomeActive:(UIApplication *)application
is called. If it is answered, then your app is told to exit and it will receive
- (void)applicationWillTerminate:(UIApplication *)application
Be sure to allow
- (void)applicationDidFinishLaunching:(UIApplication *)application
to return before running your game loop. One technique is to use the function
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
on the application delegate and run your game loop after a delay of say ".01" After you do this, the message should be able to fire properly. I believe the reason for the message stomping was because the run loop was stuck on applicationDidFinishLaunching and wasn't able to push any other UIApplicationDelegate messages onto the queue.
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active state to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}