Facebook Connect Graph API get notification when successfully sharing to facebook - ios

I use this code to share to facebook:
[appDelegate.facebook dialog:#"feed" andParams:params andDelegate:appDelegate];
How can i get the notification (like sharekit) when sharing is successful?
I want to show UIAlertView but i do not know which facebook method that i need to put the UIAlertView.
I try in this method:
- (void)dialogDidSucceed:(NSURL *)url {
if ([_delegate respondsToSelector:#selector(dialogCompleteWithUrl:)]) {
[_delegate dialogCompleteWithUrl:url];
}
UIAlertView * alert=[[UIAlertView alloc]
initWithTitle: #"Sharing to Facebook"
message: #"Success"
delegate:self
cancelButtonTitle:#"Close"
otherButtonTitles:nil, nil];
[self setAlertSuccess:alert];
[alertSuccess show];
[alert release];
NSLog(#"SUCCESS 2");
[self dismissWithSuccess:YES animated:YES];
}
It is working however, when i click cancel button, this method is also called. So where is the right one to put the success alert view?

I am new in IOS.
These are changes i made in FBDialog.m
- (void)dismissWithSuccess:(BOOL)success animated:(BOOL)animated {
if (success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook Login Sucessful!" message:#"" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
if ([_delegate respondsToSelector:#selector(dialogDidComplete:)]) {
[_delegate dialogDidComplete:self];
}
} else {
if ([_delegate respondsToSelector:#selector(dialogDidNotComplete:)]) {
[_delegate dialogDidNotComplete:self];
}
}
[self dismiss:animated];
}

Related

Opening a new view controller after alert

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
}

how to delay a popup page?

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];
}

UIAlertView showing up on Simulator, but not device

I have UIAlertView working as expected in simulator, and earlier in my App's development it worked well on the device, but as of now it doesn't show up. I am however certain the code is running. Help would be greatly appreciated.
MacroEditViewController.h:
#interface MacroEditViewController : UIViewController <UIAlertViewDelegate>
MacoEditViewController.m:
- (IBAction)saveDatabase:(UIButton *)sender
{
[self alertStatusWithTitle:[NSString stringWithFormat:#"Are you sure you want to override %# for %#? This cannot be undone (But you can Reset All Overrides on Macros screen).", macroMeal[1], macroMeal[0]] :#"Update Macros"];
}
- (void) alertStatus:(NSString *)msg :(NSString *)title
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:#"Cancel", nil];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self saveUpdatesToDatabase];
}
}
Why did you call your function like this
[self alertStatus:[#"Are you sure you want to override?"] :#"Update Macros"];
Call it like this
[self alertStatus:#"Are you sure you want to override?" :#"Update Macros"];
without the square brackets, it may be the problem
create a CIAlert.h
void CIAlert(NSString* title, NSString* alert);
void CIError(NSString* error);
and in CIAlert.m
#import "CIAlert.h"
void CIAlert(NSString* title, NSString* alert) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:alert delegate:nil
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
void CIError(NSString* error) {
CIAlert(#"Error", error);
}
import the class CIAlert.h and call it just like this...
CIAlert(#"Title", #"Enter your message");

action on textFieldDidEndEditing

I want an alert when the following text fields receive the conditions in second section of code
self.circuit.rcdAtIan = [ICUtils nonNilString:self.rcdAtIan.text];
self.circuit.rcdAt5an = [ICUtils nonNilString:self.rcdAt5an.text];
The above code works fine so now I need to fire it. Using the below method was my first thought but that fires the alert on every keyboard resignation. I only want the alert to display once.
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([_rcdAtIan.text intValue]> 200) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"my message" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
}
if ([_rcdAt5an.text intValue]> 40) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"my message" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
}
}
Im thinking maybe I need a bool with NSUserDefaults perhaps? but not sure how to implement that to check if the alert has been shown. Normally if I wanted an alert shown once I would do
if (![#"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:#"alert"]]){
[[NSUserDefaults standardUserDefaults] setValue:#"1" forKey:#"alert"];
[[NSUserDefaults standardUserDefaults] synchronize];
[alert show];
}
However in this instance, when the page is reloaded I want the alerts to be shown again and in any case im not sure if thats an efficient way to solve this
Don't use NSUserDefaults, that would be inappropriate
in your #interface...
#property (assign) BOOL freshAlert1;
#property (assign) BOOL freshAlert2;
then something like this... (assuming 'page is reloaded' equates to your viewController coming back onscreen)
- (void)viewDidAppear
{
self.freshAlert1 = YES;
self.freshAlert2 = YES;
}
if (([_rcdAtIan.text intValue]> 200) && self.freshAlert1) {
self.freshAlert1 = NO;
...
}
if (([_rcdAt5an.text intValue]> 40) && self.freshAlert2) {
self.freshAlert2 = NO;
...
}
What exactly do you mean by "once"? Once per app run, once per editing step?
Or maybe simply add two BOOL flags that you can reset whenever you want and simply to
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([_rcdAtIan.text intValue]> 200 && !alert1shown) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"my message" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
alert1shown = YES;
[alert show];
}
if ([_rcdAt5an.text intValue]> 40 && !alert2shown) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"my message" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
alert2shown = YES;
[alert show];
}
}

iOS Incompatible block pointer types issue

I have an implementation problem with a project using MKStoreKit. I am trying to implement an UIAlertView with various purchase options.
Here is the code where I do various things and call up UIAlertView:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if(FALSE == payWallFlag)
{
// Display Alert Dialog
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Subscription Options"
message:#"You do not have an active subscription. Please purchase one of the options below."
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[message addButtonWithTitle:#"7 Day Subscription $0.99"];
[message show];
return FALSE;
} else if(TRUE == payWallFlag)
{
// Load content
}
}
This is the physical alertView with the code which I am trying to call:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Cancel"])
{
NSLog(#"Cancel Button was selected.");
}
else if([title isEqualToString:#"7 Day Subscription $0.99"])
{
NSLog(#"7 Day Subscription button pressed.");
//Buy a 7 day subscription
if([SKPaymentQueue canMakePayments]) {
[[MKStoreManager sharedManager] buyFeature:kFeatureAId onComplete:^(NSString* purchasedFeature)
{
NSLog(#"Purchased: %#", purchasedFeature);
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Successful"
message:#"Thank you. You have successfully purchased a 7 Day Subscription."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Show the user the content now
payWallFlag = TRUE;
return TRUE;
}
onCancelled:^
{
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Failed"
message:#"Unfortunately you have cancelled your purchase of a 7 Day Subscription. Please try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Block the content again
payWallFlag = FALSE;
}];
}
else
{
NSLog(#"Parental control enabled");
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Failed"
message:#"Unfortunately Parental Controls are preventing you from purchasing a subscription. Please try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Block the content again
payWallFlag = FALSE;
}
}
}
The issue is I get the following Xcode error message in the UIAlertView:
Incompatible block pointer types sending 'int (^)(NSString *)' to parameter of type 'void (^)(NSString *)'
It appears the problems are: onComplete:^(NSString* purchasedFeature) and onCancelled:^ but I have no idea how to fix this.
You should not return TRUE; from that block, because then the compiler assumes that block returns an int, while it should return void (hence incompatible block types).
...onComplete:^(NSString* purchasedFeature) {
NSLog(#"Purchased: %#", purchasedFeature);
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] ...];
[alert autorelease];
[alert show];
// Show the user the content now
payWallFlag = TRUE;
return TRUE; // <--- Remove this line.
}...
For the second block (the onCancelled one), you probably missed the NSString* parameter, or whatever it expects.

Resources