Advertisement
Guest User

FB request

a guest
Apr 23rd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. - (IBAction)InviteAction:(id)sender
  2. {
  3. BOOL network = [CheckNetwork currentNetworkStatus];
  4.  
  5. if(network)
  6. {
  7. [searchbar resignFirstResponder];
  8. if (!FBSession.activeSession.isOpen)
  9. {
  10. // if the session is closed, then we open it here, and establish a handler for state changes
  11. [FBSession openActiveSessionWithReadPermissions:nil
  12. allowLoginUI:YES
  13. completionHandler:^(FBSession *session,
  14. FBSessionState state,
  15. NSError *error)
  16. {
  17. if(error)
  18. {
  19. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
  20. message:@""
  21. delegate:nil
  22. cancelButtonTitle:@"OK"
  23. otherButtonTitles:nil];
  24.  
  25. [alertView show];
  26. }
  27. else if (session.isOpen)
  28. {
  29. [self InviteAction:sender];
  30. }
  31. }];
  32. return;
  33. }
  34.  
  35. if (self.friendPickerController == nil)
  36. {
  37. // Create friend picker, and get data loaded into it.
  38. self.friendPickerController = [[FBFriendPickerViewController alloc] init];
  39. self.friendPickerController.title = @"Pick Friends";
  40. self.friendPickerController.delegate = self;
  41. }
  42.  
  43. [self.friendPickerController loadData];
  44. [self.friendPickerController clearSelection];
  45.  
  46. [self presentViewController:self.friendPickerController animated:YES completion:nil];
  47. }
  48. else
  49. {
  50. UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"No Network Available.Check your network settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  51. [alert show];
  52. }
  53. }
  54. - (void) performPublishAction:(void (^)(void)) action
  55. {
  56. if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
  57. {
  58. [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
  59. defaultAudience:FBSessionDefaultAudienceFriends
  60. completionHandler:^(FBSession *session, NSError *error)
  61. {
  62. if (!error)
  63. {
  64. action();
  65. }
  66. else if (error.fberrorCategory != FBErrorCategoryUserCancelled)
  67. {
  68. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission Denied"
  69. message:@"Unable to obtain permission to post."
  70. delegate:nil
  71. cancelButtonTitle:@"OK"
  72. otherButtonTitles:nil];
  73. [alertView show];
  74. }
  75. }];
  76. }
  77. else
  78. {
  79. action();
  80. }
  81.  
  82. }
  83.  
  84.  
  85. - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
  86. user:(id<FBGraphUser>)user
  87. {
  88. self.loggedInUser = user;
  89. }
  90.  
  91.  
  92. - (void)facebookViewControllerDoneWasPressed:(id)sender
  93. {
  94. NSMutableString *text = [[NSMutableString alloc] init];
  95. for (id<FBGraphUser> user in self.friendPickerController.selection)
  96. {
  97. if ([text length])
  98. {
  99. [text appendString:@","];
  100. }
  101. [text appendString:[NSString stringWithFormat:@"%@",user.id]];
  102. }
  103. // Its for Sending app request to selected friends
  104.  
  105. NSDictionary *params = @{@"to":text};
  106.  
  107. NSString *message = @"MESSAGE";
  108. NSString *title = @"TITLE";
  109.  
  110. [FBWebDialogs presentRequestsDialogModallyWithSession:nil
  111. message:message
  112. title:title
  113. parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
  114. {
  115. if (error)
  116. {
  117. UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Request Not Sent." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  118. [Alert show];
  119. }
  120. else
  121. {
  122. if (result == FBWebDialogResultDialogNotCompleted)
  123. {
  124. // Case B: User clicked the "x" icon
  125. UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"You have cancelled the request." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  126. [Alert show];
  127. NSLog(@"User canceled request.");
  128. }
  129. else
  130. {
  131. UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Request sent successfully." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  132. [Alert show];
  133. NSLog(@"Request Sent. %@", params);
  134. }
  135. }
  136. }];
  137.  
  138. [self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"];
  139. }
  140.  
  141.  
  142. - (void)facebookViewControllerCancelWasPressed:(id)sender {
  143. [self fillTextBoxAndDismiss:@"<Cancelled>"];
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement