I am trying to display my friends from Facebook in my app in a UITableView. However, my TableView is staying empty. Here is my code for pulling up the UITableView.
-(IBAction)testfriends {
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *innerSender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString *message;
if (friendPickerController.selection.count == 0) {
message = #"<No Friends Selected>";
} else {
NSMutableString *text = [[NSMutableString alloc] init];
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in friendPickerController.selection) {
if ([text length]) {
[text appendString:#", "];
}
[text appendString:user.name];
}
message = text;
}
[[[UIAlertView alloc] initWithTitle:#"You Picked:"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}];
}
What am I missing here? It is taken straight from the Facebook Sample, but even in the sample app, it won't work.
As of 4/30/2014, with the launch of the Graph API v2.0, you'll need to request the user_friends permission and you will only receive friends who also use the app.
Related
Integrated Paytm sdk 2.1 in iOS (Xcode 7) and configured to make payment .
I have a form in which amount and other fields need to filled then there is a button for Payment .
Here is code which i am using :
//Step 1: Create a default merchant config object
PGMerchantConfiguration *mc = [PGMerchantConfiguration defaultConfiguration];
//Step 2: If you have your own checksum generation and validation url set this here. Otherwise use the default Paytm urls
mc.checksumGenerationURL = #"generate checksum url";
mc.checksumValidationURL = #"checksum validation url";
//Step 3: Create the order with whatever params you want to add. But make sure that you include the merchant mandatory params
NSMutableDictionary *orderDict = [NSMutableDictionary new];
//Merchant configuration in the order object
orderDict[#"MID"] = #"abc1111";
orderDict[#"CHANNEL_ID"] = #"WAP";
orderDict[#"INDUSTRY_TYPE_ID"] = #"Education";
orderDict[#"WEBSITE"] = #"companyname";
//Order configuration in the order object
orderDict[#"TXN_AMOUNT"] = #"100";
orderDict[#"ORDER_ID"] = [Feepayment generateOrderIDWithPrefix:#"111"];
orderDict[#"REQUEST_TYPE"] = #"DEFAULT";
orderDict[#"CUST_ID"] = #"abc7777";
PGOrder *order = [PGOrder orderWithParams:orderDict];
//Step 4: Choose the PG server. In your production build dont call selectServerDialog. Just create a instance of the
//PGTransactionViewController and set the serverType to eServerTypeProduction
[PGServerEnvironment selectServerDialog:self.view completionHandler:^(ServerType type)
{
PGTransactionViewController *txnController = [[PGTransactionViewController alloc] initTransactionForOrder:order];
//show title var
UIView *mNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
mNavBar.backgroundColor = [UIColor grayColor];
txnController.topBar = mNavBar;
//Cancel button
UIButton *mCancelButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 70, 40)];
[mCancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
mCancelButton.titleLabel.textColor = PURPLE_COLOR;
[mCancelButton setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
txnController.cancelButton = mCancelButton;
//add title
UILabel *mTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 10, 1, 100, 50)];
[mTitleLabel setText:#"Payment"];
[mTitleLabel setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
mTitleLabel.textColor = [UIColor whiteColor];
[mNavBar addSubview:mTitleLabel];
if (type!=eServerTypeNone) {
txnController.serverType = type;
txnController.merchant = mc;
txnController.loggingEnabled = YES;
txnController.sendAllChecksumResponseParamsToPG = YES;
txnController.delegate = self;
[self showController:txnController];
}
}];
//show controller method
-(void)showController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController pushViewController:controller animated:YES];
else
[self presentViewController:controller animated:YES
completion:^{
}];
}
//remove controller
-(void)removeController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController popViewControllerAnimated:YES];
else
[controller dismissViewControllerAnimated:YES
completion:^{
}];
}
#pragma mark PGTransactionViewController delegate
- (void)didSucceedTransaction:(PGTransactionViewController *)controller
response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didSucceedTransactionresponse= %#", response);
NSString *title = [NSString stringWithFormat:#"Your order was completed successfully. \n %#", response[#"ORDERID"]];
[[[UIAlertView alloc] initWithTitle:title message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFailTransaction:(PGTransactionViewController *)controller error:(NSError *)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFailTransaction error = %# response= %#", error, response);
if (response)
{
[[[UIAlertView alloc] initWithTitle:error.localizedDescription message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
else if (error)
{
[[[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
[self removeController:controller];
}
- (void)didCancelTransaction:(PGTransactionViewController *)controller error:(NSError*)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didCancelTransaction error = %# response= %#", error, response);
NSString *msg = nil;
if (!error) msg = [NSString stringWithFormat:#"Successful"];
else msg = [NSString stringWithFormat:#"UnSuccessful"];
[[[UIAlertView alloc] initWithTitle:#"Transaction Cancel" message:msg delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFinishCASTransaction:(PGTransactionViewController *)controller response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFinishCASTransaction:response = %#", response);
}
Here is screenshot while using staging directly showing this page :
*Note - Actually i am trying for staging not for production .
When i execute then it doesnt showing Paytm feepayment form instead it showing orderid and amount with transaction id dirctly .
How to open Paytm payment form when user enter fee amount in the form then it should calcualte the amount with extraa tax and then clicking on Fee payment button it should open PAYTM PAYMENT FORM.
PLEASE HELP ME TO SOLVE THIS PROBLEM ( I HAVE GO THROUGH THE PAYTM SDK DOC STEP BY STEP BUT DINT ABLE TO FIND IT ).
THANKS.
Important : **As far as checksumGenerationURL and checksumValidationURL is concerned , we need to create it . Initially i tried to use from Paytm but it dint work so finally our server team did it , this is most important point for Integrating Paytm
Finally , Solved by testing it on the Production and its working fine . As far as Staging server is concerned i guess there is hard coded information is in the sdk so hope in the next version of PGSDK we could test it on Staging too.
Thanks .
#Pradeep k ... thank you very much for all your valuable support .
Have you populated the mc.checksumGenerationURL and mc.checksumValidationURL properly? Also there is a 2.7 version of the SDK that you should be using. Ask your Paytm contact point for the latest iOS SDK.
Now about the amount, Paytm does not calculate the tax. You have to add it to the amount that you are sending to Paytm.
i am loading tableviewcell with textfield. i am loading one array in tableview. and i have one more option called editing the textfields and changing names also. if enter same name name what it is already existed in array. that time i am showing alert but if revert back to original name i don't want to show alert
NSMutableArray *brokenCars = [NSMutableArray arrayWithObjects:
#"Audi A6", #"BMW Z3",
#"Audi Quattro", #"Audi TT", nil];
if (isEditMode)
{
if ([tempstr length]>0)
{
for (Playerinfo *player in brokenCars)
{
if ([player.playername isEqualToString:tempstr])
{
isPlayerExist = YES;
if (occurrences>1)
{
CustomAlert *alert = [[CustomAlert alloc] initWithTitle:#"" message:#"Please choose a different name" delegate:nil cancelButtonTitle:nil otherButtonTitle:#""];
[alert showInView:self.view];
NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:selectedRow inSection:0];
[_playerTable selectRowAtIndexPath:indexPath1 animated:YES scrollPosition:UITableViewScrollPositionTop];
}
}
}
}
}
I am new to iOS programming, and just want to do something fun.
I want to develop a mail client app for iPhone, it can add email accounts such as gmail and Yahoo and so on. I searched online for a while and also find some answers, before I dive into the details I just want someone who has similar experience give me some suggestions about which method is the best.
thanks
I have recently implemented gmail api to fetch gmail contacts and their email in my tableview. Gmail api is depricated, thats why you might have not got any proper documentation for that.
To implement gmail use libGDataTouchStaticLib.a library, with Gdata headers (search on google for that otherwise send me your email i will send you its zip).
The code to get gmail details are as follows
- (void)getGoogleContacts {
GDataServiceGoogleContact *service = [self contactService];
GDataServiceTicket *ticket;
BOOL shouldShowDeleted = TRUE;
// request a whole buncha contacts; our service object is set to
// follow next links as well in case there are more than 2000
const int kBuncha = 2000;
NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:kGDataServiceDefaultUser];
GDataQueryContact *query = [GDataQueryContact contactQueryWithFeedURL:feedURL];
[query setShouldShowDeleted:shouldShowDeleted];
[query setMaxResults:kBuncha];
ticket = [service fetchFeedWithQuery:query
delegate:self
didFinishSelector:#selector(contactsFetchTicket:finishedWithFeed:error:)];
[self setContactFetchTicket:ticket];
}
- (void)setContactFetchTicket:(GDataServiceTicket *)ticket {
mContactFetchTicket = ticket;
}
- (GDataServiceGoogleContact *)contactService {
static GDataServiceGoogleContact* service = nil;
if (!service) {
service = [[GDataServiceGoogleContact alloc] init];
[service setShouldCacheResponseData:YES];
[service setServiceShouldFollowNextLinks:YES];
}
// update the username/password each time the service is requested
NSString *username = [txtUserName text];
NSString *password = [txtPasswrod text];
[service setUserCredentialsWithUsername:username
password:password];
return service;
}
// contacts fetched callback
- (void)contactsFetchTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedContact *)feed
error:(NSError *)error {
if (error) {
NSDictionary *userInfo = [error userInfo];
NSLog(#"Contacts Fetch error :%#", [userInfo objectForKey:#"Error"]);
if ([[userInfo objectForKey:#"Error"] isEqual:#"BadAuthentication"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error!"
message:#"Authentication Failed"
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alertView show];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error!"
message:#"Failed to get Contacts."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alertView show];
}
} else {
NSArray *contacts = [feed entries];
NSLog(#"Contacts Count: %d ", [contacts count]);
[mutAryGoogleContacts removeAllObjects];
for (int i = 0; i < [contacts count]; i++) {
NSMutableDictionary *aDictContactDetails=[NSMutableDictionary dictionary];
GDataEntryContact *contact = [contacts objectAtIndex:i];
// Email
GDataEmail *email = [[contact emailAddresses] objectAtIndex:0];
NSString* ContactEmail = [email address];
if (ContactEmail) {
[aDictContactDetails setObject:ContactEmail forKey:#"email"];
// Name
NSString *ContactName = [[[contact name] fullName] contentStringValue];
if (ContactName) {
[aDictContactDetails setObject:ContactName forKey:#"friendName"];
}
[mutAryGoogleContacts addObject:aDictContactDetails];
}
}
//Push to next vc or do whatever you want
}
}
In Twitter ,if User has Logged In in the Twitter Account in Settings Screen It will allow to post.Or Else it will display a Alert as "No Twitter Accounts" with 2 Options "Settings" and "Cancel". If Cancel is Tapped it will close alert and reject post to twitter. And if Settings is Tapped it is not redirecting to Settings Screen.
Also i used
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
But No Luck. As far as i checked all are saying as from iOS 5.1 it wont work.But i see some apps still redirecting to settings screen in iOS7. Is it possible to redirect in iOS7.
Thanks in Advance.
You can use below code in your login button's action:
if ([TWTweetComposeViewController canSendTweet])
{
//yes user is logged in
accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
// Set the cell text to the username of the twitter account
NSString *userID = [[acct valueForKey:#"properties"] valueForKey:#"user_id"];
TwitterIdStr = [[NSString alloc] initWithString:userID];
FbIdStr = [[NSString alloc] init];
NSLog(#"%#",userID);
NSString *networkCheck = [[NSUserDefaults standardUserDefaults] valueForKey:#"isNetWorkAvailable"];
if ([networkCheck isEqualToString:#"NotConnected"])
{
// not connected
dispatch_async(dispatch_get_main_queue(), ^{
// Display/dismiss your alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No network connection" message:#"You must be connected to the internet to proceed." delegate:nil cancelButtonTitle:#"OK"otherButtonTitles:nil];
[alert show];
});
} else
{
fNameStr = [[NSString alloc] init];
lNameStr = [[NSString alloc] init];
emailStr = [[NSString alloc] init];
[self startProgressViewAgain];
}
}
}];
}
else
{
//show tweeet login prompt to user to login
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}
I got app, which can send twits.
I do it in this way:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"])
[tweet addImage:dream.image];
NSString *twitMsg = [dreamField.text stringByAppendingString:#" send via Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
//can't tweet!
}
}
What should i do when [TWTweetComposeViewController canSendTweet] is equal to NO ? And when it is equal to NO ?
That is full solution code:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"]) {[tweet addImage:dream.image];}
NSString *twitMsg = [dreamField.text stringByAppendingString:#" #Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
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:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}