iPhone .ipa file goes blank after opening splash screen? - iphone

I have created Map application and it is running on my mac machine with xcode. But when I created its ipa file and sync with my iPhone device it does not open. Only splash screen
get open and getting close. I have my developer and distribution certificate sign with device UDID. My client also could not able to run the application remotely....thanks in advance for your help. plz suggest what I am missing here??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//sleep(0.5);
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
Upadated: with leaks problems
I am also checking the possibility with memory leaks and using instrument tool I am getting 100% leaks at the time of launching the application. Its NSPlaceholderString leaks on following code...
CLLocationCoordinate2D location;
NSString *url = [NSString stringWithFormat:#"..myurl......lat=%f&lng=%f&radius=5",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude];
radiusinurl.text = #"5km";
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
**XMLParser *parser = [[XMLParser alloc] initXMLParser];** //5.3% leaks
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
**BOOL success = [xmlParser parse];** //0.2% leaks
[xmlParser release];
[parser release];
if(success)
{
NSLog(#"show me [appDelegate.markers count] %d",[appDelegate.markers count]);
annobjs = [[NSMutableArray array] retain];
if([appDelegate.markers count] == 0)
{ //99% leaks on below line where I am calling another method
**[self performSelector:#selector(showingThreeResultsOnCurrentLocation) withObject:nil];** //99% leaks
}
else
{//some logic
}
}
else
{
//logic
}}}}
I have commented leaks at the end of line. Can you correct my code. Thanks in advance...

Initialize view controller first
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //This is for autoresize when in phone call mode(which does not work yet)
[dict setObject:#"trigger" forKey:#"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"trigger"
object:self
userInfo:dict];
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
viewController = [[UIViewController alloc] initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *nav = [[UINavigaitonController alloc] initWithRootViewController:nav];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}

Related

how to check wether app is logged in or not first time [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 9 years ago.
I want the when user install apps on device app should show him loginScreen when user first time opens app after that user logins and user remains logins is there any way to make this save so that if user again opens app second then user should be in logged stated and does not show user the login screen thanks.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
self.loginViewController=[[[LoginViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
if ([detailNav.navigationBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)] )
{
UIImage *image = [UIImage imageNamed:#"Nav.png"];
[detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
user_Name=#"Jamshaid";
isClickedLogin=#"NO";
userLogin=#"Logout";
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.coffeeArray = tempArray;
[tempArray release];
NSMutableArray *tempArray1 = [[NSMutableArray alloc] init];
self.arrayOne = tempArray1;
[tempArray1 release];
NSMutableArray *tempArray2 = [[NSMutableArray alloc] init];
self.arrayTwo = tempArray2;
[tempArray2 release];
NSMutableArray *tempArray3 = [[NSMutableArray alloc] init];
self.libraryArray = tempArray3;
[tempArray3 release];
NSMutableArray *tempArray4 = [[NSMutableArray alloc] init];
self.activityArray = tempArray4;
[tempArray4 release];
NSMutableArray *tempArray5 = [[NSMutableArray alloc] init];
self.arrayOneC = tempArray5;
[tempArray5 release];
NSMutableArray *tempArray6 = [[NSMutableArray alloc] init];
self.arrayTwoC = tempArray6;
[tempArray6 release];
NSMutableArray *tempArrayD = [[NSMutableArray alloc] init];
self.detailArray = tempArrayD;
[tempArrayD release];
NSMutableArray *tempArrayD1 = [[NSMutableArray alloc] init];
self.detailArrayOne = tempArrayD1;
[tempArrayD1 release];
NSMutableArray *tempArrayD2 = [[NSMutableArray alloc] init];
self.detailArrayTwo = tempArrayD2;
[tempArrayD2 release];
NSMutableArray *tempArrayD3 = [[NSMutableArray alloc] init];
self.publishArray = tempArrayD3;
[tempArrayD3 release];
[Coffee getInitialDataToDisplay:[self getDBPath]];
// Add the split view controller's view to the window and display.
// original working [window addSubview:self.splitViewController.view];
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
I don't do iPhone development, but wouldn't this easily be achieved using a config file? For example:
App start
read config.xml
is element firstlogin false or true?
if true: show the loginscreen, once the user logs in, set element to true and save the xml.
if false: don't edit the xml at all and just skip the loginscreen.
run app
This would, of course, reset if the app is reinstalled, I figure.
Sample Code :
In yourViewController.h :
NSString *uname;
NSString *pwd;
In yourViewController.m :
- (IBAction) loginButtonClicked :(id)sender
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"])
{
// app already launched
uname = [[NSUserDefaults standardUserDefaults] valueForKey:#"UserName"];
pwd = [[NSUserDefaults standardUserDefaults] valueForKey:#"PassWord"];
//Use uname and pwd in your URL.
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// This is the first launch ever
[[NSUserDefaults standardUserDefaults] setValue:txtUserName.text forKey:#"UserName"];
[[NSUserDefaults standardUserDefaults] setValue:txtPassWord.text forKey:#"PassWord"];
}
}

iOS - Managed object context crashes app when launching from local notification

I have an app that creates a local notification. When the app is closed (i.e. not running or in the background), it crashes when being launched from the notification. I've managed to figure out which line is crashing the app (stated in a comment below):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
// Initialise the main view
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
// Initialise a Navigation Controller
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
// Set the ViewController as the rootViewController of the window
self.window.rootViewController = nav;
// Colour the navigation bar
nav.navigationBar.tintColor = [UIColor colorWithRed:0.07f green:0.59f blue:0.94f alpha:1];
// Set the background
if (isPhone568) {
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"santa_back5.png"]];
}
else {
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"santa_back.png"]];
}
[self.window makeKeyAndVisible];
[nav release];
self.viewController.managedObjectContext = [self managedObjectContext];
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSPredicate *predicate = [NSPredicate
predicateWithFormat:#"(dateCreated like %#)",
[localNotif.userInfo objectForKey:#"dateCreated"]];
LetterViewController *letterView = [[LetterViewController alloc] initWithNibName:#"LetterViewController" bundle:nil];
// Get the letter to pass on
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:#"Letter" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
NSError *error;
//
// THIS NEXT LINE IS CRASHING THE APP
//
NSArray *letters = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];
Letter *myLetter = [letters objectAtIndex:0];
letterView.theLetter = myLetter;
//[myLetter release];
// Pass the selected object to the new view controller.
[self.viewController.navigationController pushViewController:letterView animated:YES];
[letterView release];
[fetchRequest release];
}
return YES;
}
I am using the following 3 functions to get the managed object context, persistent store coordinator and managed object model:
//Explicitly write Core Data accessors
- (NSManagedObjectContext *) managedObjectContext {
if (managedObjectContext != nil) {
return managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return managedObjectContext;
}
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory]
stringByAppendingPathComponent: #"<Project Name>.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:nil error:&error]) {
/*Error for store creation should be handled in here*/
}
return persistentStoreCoordinator;
}
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
Any help in solving this problem would be greatly appreciated.
Thanks in advance.
Couple of things. You appear to be using Core Data on the main thread in what you show, if so all interaction must be on this thread. You should update the code someday to use the new 'perform' API which uses blocks.
Since your localNotif code now does some heavy lifting in the launch delegate it does not return for some time and iOS may kill your app. Take that same code and put it into dispatch block posted to the main queue and it should work. Add some asserts to insure the navigation controller property exists too.
Thanks for the answer. Seems my problem was with the predicate! It doesn't like me using "like" in the where clause. I changed it to an = and it works!

Error when using ASIHttpRequest on viewController to UISplitviewController

I have a UISplitViewController which implements a masterNavigationController and a detailNavigationController, basic from the XCode template.
The masterNavigationController calls an other NSObject called "API" which in its turn uses ASIHTTPRequest to retrieve certain JSON data from an server.
Everything is fine and dandy, until I the call from the request starts. It shows the GUI of iPad and crashes straight after with an EXC_BAD_ACCESS. The error message I get is the following:
2012-10-10 21:13:42.357 myapp[24409:c07] Splitview controller
is expected to have a view
controller at index 0 before it's used!
I have tried different things to try to solve the issue, one of them being setting the SplitViewController delegate after settings the view controllers, an other is using the NetworkQueue instead.
This is the code of the masterNavigationController:
[...]
- (void)viewDidLoad
{
[UIHelper setNavigationBackBackground:self.navigationController.navigationBar widePage:NO];
[UIHelper setViewBackground:self.parentViewController.view widePage:NO];
[UIHelper setTableViewStyle:self.tableView];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
API *api = [[API alloc] init];
[api setDelegate:self];
[api setDidFinishSelector:#selector(didFinish:)];
[api getCommingRetrievals];
}
[...]
The AppDelegate:
[...]
MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.view.opaque = NO;
self.splitViewController.view.backgroundColor = [UIColor clearColor];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
masterViewController.managedObjectContext = self.managedObjectContext;
self.splitViewController.delegate = detailViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
[...]
This is the API object's code:
- (void)getCommingRetrievals
{
[self getRetrievalsForDate:[NSDate date]];
}
- (void)getRetrievalsForDate:(NSDate*)date
{
NSString *stringFromDate = #"";
if (date != nil)
{
// Set date string
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyyMMdd"];
stringFromDate = [formatter stringFromDate:date];
}
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#/bookings/%#", API_BASE_DOMAIN, stringFromDate]];
[self callApi:url requestMethod:#"GET"];
}
#pragma mark -
#pragma mark API methods
- (void)callApi:(NSURL*)url requestMethod:(NSString*)requestMethod
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:requestMethod];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestFinished:)];
[request setDidFailSelector:#selector(didFailWithError:)];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
if (self.delegate && [self.delegate respondsToSelector:didFinishSelector]) {
[self.delegate performSelector:didFinishSelector withObject:self];
}
}
If I comment out the line [request startAsynchronous];, the app doesn't crash.
What am I missing here, and how can I solve the problem?
Check that your UISplitViewController has been passed 2 view controllers.
Other than that, some idiomatic stuff:
This should go right at the beginning of any setting up stuff:
[super viewDidLoad];
e.g. `[super viewDidLoad]` convention
And consider using another framework than ASI. It's a dead library. AFNetworking, MKNetworkingKit or RESTKit are good alternatives.

How to show load bar in ipad app while data is fetching from xml after default png is shown

I am fetching XML data from server i want that when data is loading in progress i show a loading bar with default screen this is code in appDidFinishing
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[self.window addSubview:navigationController.view];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(55, 67, 100, 100)];
[self.activityIndicator startAnimating];
[self.window addSubview:self.activityIndicator];
[self loadXMlTwo];
[self loadXMlMain];
[self performSelectorInBackground:#selector(loadXMlOne) withObject:nil];
[self.activityIndicator removeFromSuperview];
[window makeKeyAndVisible];
return YES;
}
-(void)loadXMlMain{
NSURL*url= [[NSURL alloc]initWithString:#"http://46.137.28.14/app/ipadApplic/working.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
-(void)loadXMlOne{
NSURL*url1=[[NSURL alloc] initWithString:#"http://46.137.28.14/app/ipadApplic/rowone.xml"];
NSXMLParser *xmlParserRow = [[NSXMLParser alloc] initWithContentsOfURL:url1];
//Initialize the delegate.
RowOneParser *parser1 = [[RowOneParser alloc] initXMLParser];
//Set delegate
[xmlParserRow setDelegate:parser1];
BOOL success1 = [xmlParserRow parse];
if(success1)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
-(void)loadXMlTwo{
NSURL*urlRowTwo=[[NSURL alloc] initWithString:#"http://46.137.28.14/app/ipadApplic/rowtwo.xml"];
NSXMLParser *xmlParserRowTwo = [[NSXMLParser alloc] initWithContentsOfURL:urlRowTwo];
//Initialize the delegate.
RowTwoParser *parserRowTwo = [[RowTwoParser alloc] initXMLParser];
//Set delegate
[xmlParserRowTwo setDelegate:parserRowTwo];
BOOL successRow = [xmlParserRowTwo parse];
if(successRow)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
What you need to do is unblock your main thread while you are doing background fetch of xml data. Easiest way to do that is add your fetch operations in NSOperationQueue. Set up delegates for the class which fetches the xml and handle the response.

UITabelView reloaded from NSXMLParser (iphone SDK 4.0)

I am creating application that simply reads data from an XML file and displays it in a table view.
I created a "refresh" button when clicked i want it to redownload the xml file and display it again however it seems to crash my application if there is a XML file already downloaded.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ipb = [[IPB alloc] init];
sectionTitle=[[NSMutableArray alloc]init];
currentURL=#"http://localhost:8888/xml/Sinnergy.xml";
[self reloadTableView];
[window makeKeyAndVisible];
return YES;
}
-(void)reloadTableView
{
pathURL = [NSURL URLWithString:currentURL];
parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
[mainTableView reloadData];
}
You are leaking the parser, and if its an instance variable it might cause issues. You should go
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
[parser release];
Also you are asking the parser to start parsing, but at that point of time you shouldn't be reloading the table, it should be in your
- (void)parserDidEndDocument:(NSXMLParser *)parser
delegate method. Try that and if it still crashes post the crash report