I am doing PayPal integration in my project. Everything is working, but at the end, the payment success method is not generated. My code for payment success is:
else if ([response isKindOfClass:[DoExpressCheckoutPaymentResponseDetails class]]) {
DoExpressCheckoutPaymentResponseDetails *dres = (DoExpressCheckoutPaymentResponseDetails *)response;
if (dres.PaymentInfo.count > 0 && ((PaymentInfo *)[dres.PaymentInfo objectAtIndex:0]).TransactionID.length > 0)
{
[self paymentSuccess:((PaymentInfo *)[dres.PaymentInfo objectAtIndex:0]).TransactionID];
}
else
{
NSLog(#"Error came");
[self paymentFailed];
}
}
and the payment success method is...
UINavigationController *navController = self.navigationController;
orderResultsViewController.forDelivery = ((ReviewOrderViewController *)[navController.viewControllers objectAtIndex:navController.viewControllers.count - 2]).forDelivery;
orderResultsViewController.transactionID = transactionID;
[navController popViewControllerAnimated:FALSE];
[navController setNavigationBarHidden:FALSE animated:TRUE];
[navController pushViewController:orderResultsViewController animated:TRUE];
If you got it then point me in some direction to go...
-(void)paymentFailed {
[self.navigationController popViewControllerAnimated:TRUE];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Order failed"
message:#"Your order failed. Touch \"Pay with PayPal\" to try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
I am getting above alert view and payment order failed....
Related
enter code hereI am having trouble with going back to the previous view controller when alert is presented.
What I am trying to do is have the user enter in data, then an alert appear saying it was successful, then return to the previous view controller.
I currently have no code doing so and am seeking assistance with what I should put in.
- (IBAction)saveLabel:(id)sender
{
NSArray *data = [[NSUserDefaults standardUserDefaults] objectForKey:#"DATA"];
NSMutableArray *currentDataArray;
if (data == nil)
{
currentDataArray = [[NSMutableArray alloc]init];
}
else
{
currentDataArray = [[NSMutableArray alloc]initWithArray:data];
}
[currentDataArray addObject:self.textField.text];
[[NSUserDefaults standardUserDefaults] setObject:currentDataArray forKey:#"DATA"];
}
- (IBAction)enterButtonPressed:(id)sender
{
NSLog(#"enterButtonPressed");
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[enterAlert show];
}
//If u r using dismissing
[self dismissViewControllerAnimated:YES completion:^{
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[enterAlert show];
}];
//if u r using navigation ,popViewController
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// handle completion here
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[enterAlert show];
}];
[self.navigationController popViewControllerAnimated:YES];
[CATransaction commit];
Set Delegate self of your UIAlertView
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[enterAlert show];
Use Delegate Method of UIAlertviewController.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0){
// Do your Stuff Here....
[self.navigationController popViewControllerAnimated:TRUE];
}
}
Add the following UIAlertViewDelegate method to your implementation file:
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex {
// If you are presenting this view controller
[self dismissViewControllerAnimated:YES completion:nil];
// If you are pushing this view controller
[self.navigationController popViewControllerAnimated:YES];
}
Also remember to set your UIAlertView delegate to your view controller, change to the following code:
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
UIAlertView *enterAlert = [[UIAlertView alloc]initWithTitle:nil message:#"Entry was recorded" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
enterAlert.tag=100;
[enterAlert show];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (alertView.tag == 100) {
if (buttonIndex == 0) {
// Do something when ok pressed
// If you are presenting this view controller
[self dismissViewControllerAnimated:YES completion:nil];
// If you are pushing this view controller
[self.navigationController popViewControllerAnimated:YES];
} else {
// Do something for other alertviewButton}
else{// Do something with responses from other alertViews by giving tags
}
What is wrong with following code? I will change the viewController, when the text in the alertView is not empty. The problem is, it will change the UiViewController every time, even it is empty.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([[alertView textFieldAtIndex:0].text isEqual:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error warning" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"ChangeView"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}
You should do this check instead:
if (![[alertView textFieldAtIndex:0].text.length) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error warning" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
} else ...
I just built an Activity indicator view, and a popup page in Xcode. How can I get a 3 second delay in Activity indicator view, then switch to popup page?
here is my Viewcontroller.m
- (IBAction)Connect:(UIButton *)sender forEvent:(UIEvent *)event
{
[self performSelector:#selector(delay2) withObject:Nil afterDelay:6.0];
[self performSelector:#selector(delay1) withObject:ConnectAct afterDelay:0.0];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"LP01;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
[alert show];
}
- (IBAction)ConnectLP02:(UIButton *)sender
{
[self performSelector:#selector(delay2) withObject:Nil afterDelay:6.0];
[self performSelector:#selector(delay1) withObject:ConnectAct afterDelay:0.0];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"LP02;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
[alert show];
}
- (void)delay1 {
ConnectAct.alpha = 1.0;
}
- (void)delay2 {
}
- (IBAction)ConnectLP02:(UIButton *)sender
{
[self performSelector:#selector(delay2) withObject:Nil afterDelay:6.0];
[self performSelector:#selector(delay1) withObject:ConnectAct afterDelay:0.0];
}
- (void)delay1 {
ConnectAct.alpha = 1.0;
}
- (void)delay2 {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"LP02;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
[alert show];
}
After a lot of searching on here I finally found a way for Game Center to display in SpriteKit but now I can't get the leaderboardViewControllerDidFinish method to call. I use this code in a different app and it works fine but for some reason with the code being modified for SpriteKit its just not working. Thank you in advance!
Here is a sample of my code:
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *leaderboardViewController = [[GKGameCenterViewController alloc] init];
if (leaderboardViewController != NULL)
{
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: leaderboardViewController animated: YES completion:nil];
}
}
}
}
- (void)leaderboardViewControllerDidFinish:(GKGameCenterViewController *)viewController {
NSLog(#"in leaderboardControllerDidFinish");
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
To answer my own question...
I just took the code straight from Apple
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: gameCenterController animated: YES completion:nil];
}
}
}
}
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController {
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
I'm creating an application that has integration with Twitter .. and wanted to know what have to do to create a button to add an image of the device in the tweet.and also wanted to know which framework to use it and also where the code
You can just use the twitter framework, it's included since iOS 5
And the code i use:
- (IBAction)twitter:(id)sender {
if([TWTweetComposeViewController canSendTweet])
{
NSLog(#"Ready to Tweet.");
TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer setInitialText:[NSString stringWithFormat:#"My message"]];
[tweetComposer addImage:[UIImage imageNamed:#"114x114"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://myPage"]];
tweetComposer.completionHandler = ^(TWTweetComposeViewControllerResult result){
if(result == TWTweetComposeViewControllerResultDone){
NSLog(#"Tweeted.");
} else if(result == TWTweetComposeViewControllerResultCancelled) {
NSLog(#"Cancelled.");
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
};
[self presentModalViewController:tweetComposer animated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}