'wait_fences: failed to receive reply: 10004003' in iPhone - iphone

My application crash when I pop to root view controller in click event of UIAlertView.
my code as below :
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0 && ([errorCodeNew isEqualToString:#"IPH_I_LGN_002"])){
[self.navigationController popToRootViewControllerAnimated:YES];
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:#"3" forKey:#"CurrentSize"];
NSMutableArray *nsmarrJpName;
DatabaseLogic *logic = [[DatabaseLogic alloc] init];
appDelegate.anket_id = [logic getAnketID];
nsmarrJpName = [[NSMutableArray alloc]initWithArray:[logic getDetailScreenItems:[logic getAnketID]] copyItems:YES];
for (int i = 0; i < [nsmarrJpName count]; i++) {
NSString *strKey = [nsmarrJpName objectAtIndex:i];
[defaults setObject: [NSNumber numberWithBool:YES] forKey:strKey];
NSLog(#"key : %#", strKey);
}
[nsmarrJpName removeAllObjects];
[nsmarrJpName release];
appDelegate.strUserFlg = [logic getUserType];
[logic release]; logic = nil;
//start download process
[[NSNotificationCenter defaultCenter] postNotificationName:LOGIN_COMPLETE_NOTIFICATION object:self userInfo:nil];
}else{
NSLog(#"cancel");
}
}
I have tried by replacing clickedButtonAtIndex with didDismissWithButtonIndex method. But I does not get any result.
Thanks.

Try moving the [self.navigationController popToRootViewControllerAnimated:YES] to the bottom of the function (i.e. after all the other code has run).

Related

NSUserDefaults not getting stored string value

I have UIWebView for reading content. After that i select some text from content stores in string using NSUserDefaults in Viewcontroller. Then i retrieve this string value and displays in UITextView to viewcontroller1. But the UITextView is not updating text from viewcontroller. The NSUserDefaults also not getting updating text. Im using [self.navigationController pushViewController:viewcontroller1 animated:YES]; for switch to viewcontroller1.
viewcontroller:
[wbCont loadHTMLString:webString baseURL:nil];
[self.view addSubview:wbCont];
NSMutableArray *items = [[[UIMenuController sharedMenuController] menuItems] mutableCopy];
if (!items) items = [[NSMutableArray alloc] init];
UIMenuItem *menuItem;
menuItem = [[UIMenuItem alloc] initWithTitle:#"BookMark" action:#selector(save:)];
[items addObject:menuItem];
[menuItem release];
menuItem = [[UIMenuItem alloc] initWithTitle:#"Note" action:#selector(note:)];
[items addObject:menuItem];
[menuItem release];
[[UIMenuController sharedMenuController] setMenuItems:items];
[items release];
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(save:))
{
return YES;
}
else if (action == #selector(note:))
{
return YES;
}
else if (action == #selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
-(void)save:(id)sender{
NSString *selection = [wbCont stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
NSLog(#"selection is %#",selection);
NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults];
[userData1 setObject:selection forKey:#"preferenceName"];
[userData1 synchronize];
[self.navigationController pushViewController:note animated:YES];
}
viewcontroller1:
textView = [[UITextView alloc]initWithFrame:CGRectMake(0,0,320,400)];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *savedValue = [prefs stringForKey:#"preferenceName"];
NSLog(#"saved is %#", savedValue);
textView.text = [NSString stringWithFormat:#"%#", savedValue];
Allocation of textView is in viewDidLoad.
Updating of textView is in viewWillAppear.
-(void) viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *savedValue = [prefs stringForKey:#"preferenceName"];
NSLog(#"saved is %#", savedValue);
textView.text = [NSString stringWithFormat:#"%#", savedValue];
}
I was checked your code just change NSSTring to NSString like below it will working.
-(void)save:(id)sender{
// NSSTring *selection = [wbCont stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
NSString *selection = [wbCont stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
NSLog(#"selection is %#",selection);
NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults];
[userData1 setObject:selection forKey:#"preferenceName"];
[userData1 synchronize];
[self.navigationController pushViewController:note animated:YES];
}

Just cannot figure out how to reloadData in UITableView using a navigationController

This is my first time asking a question & posting code so I hope I have included everything that is necessary.
In several of my other apps I have been able to successfully reloadData in a UITableView but for some reason I cannot get it to work here.
I am using a navigationController and drilling down a few levels in the UITableView until a new class loads which right now just has two buttons that switch between 2 similar plist files so I can tell that the tableView is actually reloading (Data.plist & Data2.plist)
This is eventually going to be a timesheet sort of app where individual jobs are listed and the user (driver) will punch a timeclock with In/Out buttons. For now, what I want is to drill down and click the button that loads the other plist and go back up to reveal that the new plist data has loaded. My problem is that I cannot get the tableView to reload at all. I've tried putting different variations of [self.tableView reloadData] & [myTableView reloadData] (which I have also connected via IB) all over the place but none of them work. I'm currently calling a method in the rootViewController (where the tableView is) from detailViewController (where the buttons are) and that basic process works for me in other apps when there is no navigationController being used. The navigationController seems to be throwing me off here in this app. I hope an easy solution can be found. My code so far looks like this:
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
//THIS ESTABLISHES WHICH PLIST TO LOAD BASED ON THE BUTTON CLICKED
plistToUse = [[NSUserDefaults standardUserDefaults] objectForKey:#"plistToUse"];
if (plistToUse == #"Data.plist") {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:#"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
} else if (plistToUse == #"Data2.plist") {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:#"Data2.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
} else {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:#"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
}
if(CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
self.tableDataSource = [self.data objectForKey:#"Rows"];
self.navigationItem.title = #"Choose Driver";
} else if (CurrentLevel == 1) {
self.navigationItem.title = #"Choose Day";
} else if (CurrentLevel == 2) {
self.navigationItem.title = #"Choose Job";
} else if (CurrentLevel == 3) {
self.navigationItem.title = #"Job Details";
} else {
self.navigationItem.title = CurrentTitle;
}
}
-(void)update {
dvController.labelHelper.text = #"UPDATED"; //USED TO SEE IF A LABEL IN THE BUTTON CLASS WILL UPDATE
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
self.tableDataSource = [self.data objectForKey:#"Rows"];
self.navigationController.navigationItem.title = #"Choose Driver";
self.navigationController.title = #"THE TITLE";
[myTableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
unsortedIndex=1;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tableDataSource count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:#"Title"];
NSArray *Children = [dictionary objectForKey:#"Children"];
if ([Children count] == 0) {
Titles = [dictionary objectForKey:#"Title"];
in1 = [[NSUserDefaults standardUserDefaults] objectForKey:#"InTime1"];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#", in1];
}
in1 = [[NSUserDefaults standardUserDefaults] objectForKey:#"InTime1"];
out1 = [[NSUserDefaults standardUserDefaults] objectForKey:#"OutTime1"];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#:%#", in1, out1];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
NSArray *Children = [dictionary objectForKey:#"Children"];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
if([Children count] == 0) {
[self.navigationController pushViewController:dvController animated:YES];
dvController.labelSiteName.text = [dictionary objectForKey:#"Company"];
dvController.labelSiteAddress.text = [dictionary objectForKey:#"Address"];
dvController.labelSiteNotes.text = [dictionary objectForKey:#"Notes"];
[dvController.mapView setMapType:MKMapTypeStandard];
[dvController.mapView setZoomEnabled:YES];
[dvController.mapView setScrollEnabled:YES];
dvController.mapView.showsUserLocation = YES;
[dvController release];
}
else {
RootViewController *rvController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:[NSBundle mainBundle]];
rvController.CurrentLevel += 1;
rvController.CurrentTitle = [dictionary objectForKey:#"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource = Children;
[rvController release];
}
}
DetailViewController.m
These are the two buttons that should reload the tableView with either Data.plist or Data2.plist
-(IBAction)getInTime1:(id)sender {
plistToUse = #"Data.plist";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:plistToUse forKey:#"plistToUse"];
[defaults synchronize];
[rvController update];
}
-(IBAction)getOutTime1:(id)sender {
plistToUse = #"Data2.plist";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:plistToUse forKey:#"plistToUse"];
[defaults synchronize];
[rvController update];
}
I appreciate any help you can give.
Add your data fetching from plist code into your viewDidAppear or viewWillAppear methods, so that each time view appears, the data is loaded from plist.
And also note that your arrays are allocated only once.
This will work for you.

Code works fine on iOS5 but not on iOS4.3

I have code that works fine on iOS5 but does not work on iOS4.3, I'm trying to display a loading screen with a progress bar from a navigation controller that has a UIViewController as the root view.
The problem is that on iOS4.3 the loading screen doesn't appear at the right time, it appears just before the view of the second view controller is displayed and then disappears quickly.
Here's the code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
CGSize s = [[UIScreen mainScreen] bounds].size;
[standardUserDefaults setObject:#"" forKey:#"display_resolution"];
if((int)s.width == 640 && (int)s.height == 960)[standardUserDefaults setObject:#"#2x" forKey:#"display_resolution"];
[standardUserDefaults synchronize];
AC_Loading *loading = [[[AC_Loading alloc] initWithNibName:#"AC_Loading_iPhone" bundle:nil] autorelease];
_navController0 = [[[UINavigationController alloc]initWithRootViewController:loading]autorelease];
_navController0.navigationBar.hidden = YES;
self.window.rootViewController = self.navController0;
[self.window makeKeyAndVisible];
return YES;
}
-
Edit
I figured out that the problem came from AC_Loading's code, this UIViewController has to display a loading screen with a progress view that updates according to database stat (I'm creating a sqlite3 database and updating it if needed and showing progress).While using this code on iOS5 works but it doesn't on iOS4.x I thought is because of the loop inside viewDidAppear (While pr<1.0):
#import "AC_Loading.h"
#import "database.h"
#import "AC_Menu.h"
#implementation AC_Loading
#synthesize logo;
#synthesize progress;
#synthesize informations;
#synthesize CLController;
float pr = 0.14;
int p = 0;
AC_Menu *menu;
NSUserDefaults *standardUserDefaults;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:#"NO" forKey:#"geoloc"];
[standardUserDefaults synchronize];
NSLog(#"%#", [NSString stringWithFormat:#"intro%#%#", [standardUserDefaults stringForKey:#"display_resolution"], #".jpg"]);
[logo setImage:[UIImage imageNamed:[NSString stringWithFormat:#"intro%#%#", [standardUserDefaults stringForKey:#"display_resolution"], #".jpg"]]];
//[progress setProgressTintColor:[UIColor purpleColor]];
[progress setProgress:0.14];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setLogo:nil];
[self setInformations:nil];
[self setProgress:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
database *DB = [[database alloc] init];
[DB checkDB];
NSString *message = #"Chargement des données";
if([DB isCreated]== NO && [DB upToDate] == NO && sqlite3_open([[DB getDBPath:[NSString stringWithFormat:#"%#%#%#", #"Restaurant_V", [DB getVersion], #".sqlite" ]] UTF8String], [DB getDB]) == SQLITE_OK)
{
message = #"Mise à jour des données";
[DB setExecuting:YES];
[NSThread detachNewThreadSelector:#selector(createDB) toTarget:DB withObject:nil];
while([DB isExecuting]==YES)
{
if([DB isExecuting]==NO) break;
}
NSLog(#"Cas 1");
}
if([DB isCreated]== YES && [DB upToDate] == NO && sqlite3_open([[DB getDBPath:[NSString stringWithFormat:#"%#%#%#", #"Restaurant_V", [DB getVersion], #".sqlite" ]] UTF8String], [DB getDB]) == SQLITE_OK)
{
[DB setExecuting:YES];
[NSThread detachNewThreadSelector:#selector(updateDB:) toTarget:DB withObject:[DB getVersion]];
while([DB isExecuting]==YES)
{
if([DB isExecuting]==NO) break;
}
NSLog(#"Cas 2");
}
int p = floor([progress progress]*100);
while (pr<1.0)
{
p = floor(pr*100);
if(p%14==0)
{
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0, true);
[progress setProgress:pr];
[informations setText:[NSString stringWithFormat:#"%# (%d%#", message, p, #"%)"]];
}
pr += 0.000002;
}
[progress setProgress:1.0];
[informations setText:[NSString stringWithFormat:#"%# (100%#", message, #"%)"]];
menu =
[[[AC_Menu alloc] initWithNibName:#"AC_Menu_iPhone" bundle:nil] autorelease];
[self.navigationController pushViewController:menu animated:YES];
[DB release];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
}
- (void)dealloc {
[CLController release];
[logo release];
[informations release];
[progress release];
[super dealloc];
}

Consumable product is acting strange and making duplicate requests.. What could be the cause?

I am doing in app purchase on two of my controllers say view1,view2.
when I buy a consumable product in view1 everything works fine.
but when I buy another consumable product on view2 after the transaction is complete it fires the old request I made on view1 and not the new view2 request. And vice versa
Also if I rebuy the same product from same controller after rebuying it makes the request which I made before it...
Example:
Controller1:
product1 > buy > someaction(say hit to the server with some params like "name= ABC")
user enters name and is dynamic
Again,
if I rebuy it
product1 > buy > someaction(say hit to the server with some params like "name= XYZ")
Now when product is bought it hits the server with old params "name=ABC" and not "name=XYZ" what user enters again..
product
**heres the code m using in my IAPhelper**
- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers {
if ((self = [super init])) {
// Store product identifiers
_productIdentifiers = [productIdentifiers retain];
// Check for previously purchased products
NSMutableSet * purchasedProducts = [NSMutableSet set];
for (NSString * productIdentifier in _productIdentifiers) {
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased) {
[purchasedProducts addObject:productIdentifier];
NSLog(#"Previously purchased: %#", productIdentifier);
}
NSLog(#"Not purchased: %#", productIdentifier);
}
self.purchasedProducts = purchasedProducts;
}
return self;
}
- (void)requestProducts {
self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers] autorelease];
_request.delegate = self;
[_request start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(#"Received products results...");
self.products = response.products;
self.request = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:kProductsLoadedNotification object:_products];
}
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
// TODO: Record the transaction on the server side...
}
- (void)provideContent:(NSString *)productIdentifier {
NSLog(#"Toggling flag for: %#", productIdentifier);
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:productIdentifier];
[[NSUserDefaults standardUserDefaults] synchronize];
// [_purchasedProducts addObject:productIdentifier];
[[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchasedNotification object:productIdentifier];
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(#"completeTransaction...");
[self recordTransaction: transaction];
[self provideContent: transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(#"restoreTransaction...");
[self recordTransaction: transaction];
[self provideContent: transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void)failedTransaction:(SKPaymentTransaction *)transaction {
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(#"Transaction error: %#", transaction.error.localizedDescription);
}
[[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchaseFailedNotification object:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void)buyProductIdentifier:(NSString *)productIdentifier {
NSLog(#"Buying in IAPHelper %#...", productIdentifier);
SKPayment *payment = [SKPayment paymentWithProductIdentifier:productIdentifier];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void)dealloc
{
[_productIdentifiers release];
_productIdentifiers = nil;
[_products release];
_products = nil;
[_purchasedProducts release];
_purchasedProducts = nil;
[_request release];
_request = nil;
[super dealloc];
}
#end
**heres the code m using in my view1controller**
-(void)viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(productPurchased:) name:kProductPurchasedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: #selector(productPurchaseFailed:) name:kProductPurchaseFailedNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(productsLoaded:) name:kProductsLoadedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(#"No internet connection!");
} else {
if ([InAppRageIAPHelper sharedHelper].products == nil) {
[[InAppRageIAPHelper sharedHelper] requestProducts];
// self.hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
_hud.labelText = #"Loading comics...";
// [self performSelector:#selector(timeout:) withObject:nil afterDelay:30.0];
}
}
}
- (void)productPurchased:(NSNotification *)notification {
[self removeLoader];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
NSString *productIdentifier = (NSString *) notification.object;
NSLog(#"Purchased: %#", productIdentifier);
NSString *inaapstatus =[[NSUserDefaults standardUserDefaults] objectForKey:#"inaapstatus"];
if ([inaapstatus isEqualToString:#"addabeep"]) {
NSUserDefaults *inaapstatus = [NSUserDefaults standardUserDefaults];
[inaapstatus setValue:#"reset" forKey:#"inaapstatus"];
[[NSUserDefaults standardUserDefaults]synchronize];
if ([productIdentifier isEqualToString:#"com.beepbXXXXXXXX"]) {
duration = #"30";
NSUserDefaults *purchased = [NSUserDefaults standardUserDefaults];
[purchased setValue:#"YES" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(purchased:) userInfo:nil repeats:NO];
}
else {
duration = #"7";
NSUserDefaults *purchased = [NSUserDefaults standardUserDefaults];
[purchased setValue:#"YES" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(purchased:) userInfo:nil repeats:NO];
}
}
else
{
}
// [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(makeMyBeeps1Request:) userInfo:nil repeats:NO];
}
-(void)purchased:(NSTimer *)timer
{
NSString *purchased =[[NSUserDefaults standardUserDefaults] objectForKey:#"purchased" ];
if ([purchased isEqualToString:#"YES"]) {
[self doLogin];
NSUserDefaults *purchased1 = [NSUserDefaults standardUserDefaults];
[purchased1 setValue:#"NO" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
- (void)productPurchaseFailed:(NSNotification *)notification {
[self removeLoader];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
// [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
SKPaymentTransaction * transaction = (SKPaymentTransaction *) notification.object;
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Oops error occcured!"
message:transaction.error.localizedDescription
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil] autorelease];
[alert show];
//[alert release];
}
}
- (void)dismissHUD:(id)arg {
NSLog(#"dismissHUD");
[self removeLoader];
}
- (void)productsLoaded:(NSNotification *)notification {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
// [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
[self removeLoader];
}
- (void)timeout:(id)arg {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Timeout!"
message:#"Please try again later."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil] autorelease];
[alert show];
// [alert release];
//[self performSelector:#selector(dismissHUD:) withObject:nil afterDelay:3.0];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//self.hud = nil;
// self.table.hidden = TRUE;
inappObserver = [[InAppPurchaseObserver alloc] init];
if ([SKPaymentQueue canMakePayments]) {
// Yes, In-App Purchase is enabled on this device!
// Proceed to fetch available In-App Purchase items.
// Replace "Your IAP Product ID" with your actual In-App Purchase Product ID,
// fetched from either a remote server or stored locally within your app.
SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects:#"com.beepccccceek1",#"com.beepbcccccnth1", nil ]];
prodRequest.delegate = self;
[prodRequest start];
} else {
// Notify user that In-App Purchase is disabled via button text.
[inappButton setTitle:#"In-App Purchase is Disabled" forState:UIControlStateNormal];
inappButton.enabled = NO;
}
[super viewDidLoad];
[self initializeView];
}
**view2 controller**
#pragma mark - View lifecycle
-(void)viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(productPurchased:) name:kProductPurchasedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: #selector(productPurchaseFailed:) name:kProductPurchaseFailedNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(productsLoaded:) name:kProductsLoadedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(#"No internet connection!");
} else {
if ([InAppRageIAPHelper sharedHelper].products == nil) {
[[InAppRageIAPHelper sharedHelper] requestProducts];
// self.hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
[self performSelector:#selector(timeout:) withObject:nil afterDelay:30.0];
}
}
}
- (void)viewDidLoad
{
inappObserver = [[InAppPurchaseObserver alloc] init];
if ([SKPaymentQueue canMakePayments]) {
// Yes, In-App Purchase is enabled on this device!
// Proceed to fetch available In-App Purchase items.
// Replace "Your IAP Product ID" with your actual In-App Purchase Product ID,
// fetched from either a remote server or stored locally within your app.
SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects:#"com.beepbccccecc1",#"com.beepcccp.month1",#"com.beeccccep.free", nil ]];
prodRequest.delegate = self;
[prodRequest start];
} else {
// Notify user that In-App Purchase is disabled via button text.
[inappButton setTitle:#"In-App Purchase is Disabled" forState:UIControlStateNormal];
inappButton.enabled = NO;
}
[super viewDidLoad];
[self initializeView];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.mTableView = nil;
self.numberofbeeps = nil;
self.segmentedControl = nil;
}
- (void)productPurchased:(NSNotification *)notification {
[self removeLoader];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
NSString *productIdentifier = (NSString *) notification.object;
NSLog(#"Purchased: %#", productIdentifier);
NSString *inaapstatus =[[NSUserDefaults standardUserDefaults] objectForKey:#"inaapstatus"];
if ([inaapstatus isEqualToString:#"expired"]) {
NSUserDefaults *inaapstatus = [NSUserDefaults standardUserDefaults];
[inaapstatus setValue:#"reset" forKey:#"inaapstatus"];
[[NSUserDefaults standardUserDefaults]synchronize];
if ([productIdentifier isEqualToString:#"com.beepbccccnth1"]) {
duration = #"30";
NSUserDefaults *purchased = [NSUserDefaults standardUserDefaults];
[purchased setValue:#"YES" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(purchased:) userInfo:nil repeats:NO];
}
else {
duration = #"7";
NSUserDefaults *purchased = [NSUserDefaults standardUserDefaults];
[purchased setValue:#"YES" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(purchased:) userInfo:nil repeats:NO];
}
}
else
{
}
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(makeMyBeeps1Request:) userInfo:nil repeats:NO];
}
-(void)purchased:(NSTimer *)timer
{
NSString *purchased =[[NSUserDefaults standardUserDefaults] objectForKey:#"purchased" ];
if ([purchased isEqualToString:#"YES"]) {
[self durationRequest];
NSUserDefaults *purchased = [NSUserDefaults standardUserDefaults];
[purchased setValue:#"NO" forKey:#"purchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
- (void)productPurchaseFailed:(NSNotification *)notification {
[self removeLoader];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
// [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
SKPaymentTransaction * transaction = (SKPaymentTransaction *) notification.object;
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Oops error occcured!"
message:transaction.error.localizedDescription
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil] autorelease];
[alert show];
//[alert release];
}
}
- (void)dismissHUD:(id)arg {
NSLog(#"dismissHUD");
[self removeLoader];
}
- (void)productsLoaded:(NSNotification *)notification {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
// [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
[self removeLoader];
}
- (void)timeout:(id)arg {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Timeout!"
message:#"Please try again later."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil] autorelease];
[alert show];
// [alert release];
//[self performSelector:#selector(dismissHUD:) withObject:nil afterDelay:3.0];
}
Any help is appreciated thnx a lot guys
I don't recommend you having more than one active purchase delegate at a time. Try to deactivate the first delegate in view1 after all process succeeds, and then make the purchase in view2, see if that happens again
Sorry couldnt get time to update my answer.
I solved it by removingObserver of the notification posted just after the notification request completes...
Hope it helps someone..

How to make my method run when the view re-load

I want to create a login button. When I click it the facebook launches, I accept my application, the Facebook application closes and my application reloads. My problem is that the second time my application starts, after accepting on Facebook, I cannot find where to disable the login button.
I wrote this code:
-(IBAction) login:(id)sender;
{
AutoAppDelegate *delegate = (AutoAppDelegate *) [[UIApplication sharedApplication] delegate];
// Check and retrieve authorization information
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
[delegate facebook].accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
[delegate facebook].expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![[delegate facebook] isSessionValid]) {
[delegate facebook].sessionDelegate = self;
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_likes",
#"read_stream",
nil];
[[delegate facebook] authorize:permissions];
} else {
logIn.hidden=YES;
lbl.text=#"";
lbl.text=#"Connected";
[self showLoggedIn];
}
}
- (void) showLoggedIn {
NSLog(#"11 Logged In ");
lbl.text=#"";
lbl.text=#"Connected";
}
- (void) showLoggedOut {
NSLog(#"11 Not Logged In ");
lbl.text=#"";
lbl.text=#"Not Connected";
}
- (void) viewWillAppear:(BOOL)animated
{
//[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
AutoAppDelegate *delegate = (AutoAppDelegate *) [[UIApplication sharedApplication] delegate];
// Check and retrieve authorization information
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
[delegate facebook].accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
[delegate facebook].expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![[delegate facebook] isSessionValid]) {
// [self showLoggedOut];
NSLog(#"Not Connected");
} else {
// [self showLoggedIn];
NSLog(#"Connected");
}
}
The viewWillAppear works the first time, but when I give permissions in the Facebook application, my application restarts but not viewWillAppear method!
You need to put the code in your application delegate (applicationWillEnterForeground), as it's the only thing to get notified automatically when the app is re-opened (your view is not necessarily re-drawn).
Have you tried to calling setNeedsDisplay on the view after the Facebook thing is done?