I am a iPhone beginner and i want to know how many parameters the main function takes.
you generally don't touch the main method.
typically you begin entering your code in your application delegate, specifically:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
The main() function is a standard C main(). It takes two parameters:
int main(int argc, char *argv[]) {}
As Isaac notes, usually you will use the main.m provided for you by XCode:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Related
I have a problem integrating Facebook SDK 3.2 with my app, my app goes to facebook app for approval and login, but when
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
needs to be called when facebook authorization is done, it simply skips it.
It works great when I force webView facebook login via modal viewcontroller, but when I want to use installed facebook app/safari it just doesn't work.
Any suggestions?
Thank you.
Make sure you put UIApplicationDelegate in interface declaration.
#interface AppDelegate : NSObject <UIApplicationDelegate>
Also verify its right App delegate class
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
[pool release];
return retVal;
}
Also add fb Id in plist.
I'm having a problem with my iPhone App, I'm getting EXC_BAD_ACCESS, I had some memory leaks, but these are now fixed, so I'm not sure whats going on. I realise that I haven't provide a lot of information, but I really don't know whats happening.
The initial screen opens up where I have a number of buttons. Tapping on the first button, which runs the following code and opens up a modal view:
-(IBAction)newWorkoutButton
{
newWorkoutViewController .loadedFromRootViewController = #"YES";
[self presentModalViewController:newWorkoutViewController animated:YES];
}
The screen freezes and the is in the code below:
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <CoreLocation/CoreLocation.h>
int main(int argc, char *argv[])
{
Method getDistanceFrom = class_getInstanceMethod([CLLocation class], #selector(getDistanceFrom:));
class_addMethod([CLLocation class], #selector(distanceFromLocation:), method_getImplementation(getDistanceFrom), method_getTypeEncoding(getDistanceFrom));
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); // ERROR HAPPENING HERE
[pool release];
return retVal;
}
Like Aleks suggested you can try to find the zombie like this:
I find this alternative more convenient:
Click the "Run Button Dropdown"
From the list choose Profile
The program "Instruments" should open where you can also choose Zombies
Now you can interact with your app and try to cause the error
As soon as the error happens you should get a hint on when your object was released and therefore deallocated.
(source: dimzzy.com)
I am making an application which logs in using some username and password. Now when i am logged in succesfully I want my application to be logged out automatically if no interaction with the application found for 10-12 minutes.
Can anybody guide me how can i achieve this ??
Help with some code will be really appreciated.
Thanks
The Thing you want to implement is called SESSION MANAGEMENT.You have to subclass the UIApplication.
#interface MyUIApp : UIApplication {
}
In this class you have to reset the timer each time. Also you have to check if the application is responded or not with this.If the idleTimer is Exceeded then push the viewController to your login view.
- (UIResponder *)nextResponder {
[self resetIdleTimer];
return [super nextResponder];
}
Also you have to change the main class file with this:-
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSString* appClass = #"MyUIApp";
NSString* delegateClass = nil;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
[pool release];
return retVal;
}
Now I am using Three20 in my apps. I have a problem, when I run the application with MainWindow.xib, the TTTableview class isn't called. But without MainWindow.xib it would call the TTTableview class. I don't know why it's happening. Please help me out.
Thanks.
In your AppDelegate code
delete the mainWindow.xib
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
if (![navigator restoreViewControllers]) {
[navigator openURLAction:[TTURLAction actionWithURLPath:kAppRootURLPath]];
}
}
In main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"YOURAppDelegate");
[pool release];
return retVal;
}
i have used autorelease throughout my app and would like to understand the behavior of the autorelease method. When is the default autorelease pool drained? is it based on a timer (every 30sec?) or have to be called manually? do I need to do anything to release variables that are flagged with autorelease?
There are (I'd say) 3 main instances when they are created and release:
1.Beginning and very end of your application life-cycle, written in main.m
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
2.Beginning and very end of each event (Done in the AppKit)
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)loadView
/* etc etc initialization stuff... */
[pool release];
3.Whenever you want (you can create your own pool and release it. [from apples memory management document])
– (id)findMatchingObject:anObject {
id match = nil;
while (match == nil) {
NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
/* Do a search that creates a lot of temporary objects. */
match = [self expensiveSearchForObject:anObject];
if (match != nil) {
[match retain]; /* Keep match around. */
}
[subPool release];
}
return [match autorelease]; /* Let match go and return it. */
}
It is drained whenever the current run-loop finishes. That is when your method and the method calling your method and the method calling that method and so on is all done.
From the documentation:
The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event