IOS 8 how to post messages, images on facebook, Twitter community page - ios

IOS 7, 8 how to post messages, images on Facebook, Twitter community page's wall. I tried with SLComposeViewController and it is possible to post in logged in user's wall but didn't see how to post to a Facebook or Twitter community or page wall.

You can do this with UIActivityViewController.Create a button outlet And write the below code in IBAction.
- (IBAction)Share:(id)sender{
NSString *shareString=[NSString stringWithFormat:#"Write here what you want to share"];
NSArray * itemsArray = #[[NSString stringWithFormat:#"%#",shareString]];//if you want to share image here pass url of image in the array.
NSArray * applicationActivities = nil;
UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
[self presentViewController:AVC animated:YES completion:nil];
[AVC setCompletionHandler:^(NSString *act, BOOL done)
{
NSString *ServiceMsg = nil;
if([act isEqualToString:UIActivityTypeMail]) {
ServiceMsg = #"Mail sent!";
} else if([act isEqualToString:UIActivityTypePostToTwitter]) {
ServiceMsg = #"Shared on twitter!";
} else if([act isEqualToString:UIActivityTypePostToFacebook]) {
ServiceMsg = #"Shared on facebook!";
} else if([act isEqualToString:UIActivityTypeMessage]) {
ServiceMsg = #"SMS sent!";
} else if([act isEqualToString:UIActivityTypeAddToReadingList]) {
ServiceMsg = #"Added to Reading List";
} else if([act isEqualToString:UIActivityTypeCopyToPasteboard]){
ServiceMsg = #"Link Copied";
}
if ( done )
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:#"" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
[Alert show];
}
}];
}
Hope it will help you.

Related

How to block to open default Facebook sharing in UIActivityViewController in iOS?

in my application want to open custom pop up in UIActivityViewController. So i don't want to open default sharing pop up in facebook. So how to dismiss that pop up or how to block to open that pop up in iOS.
Please give me solution ...
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissPopup) name:dismissMJPopUp object: nil];
//ReferFriendVC *okpopup=[[ReferFriendVC alloc]initWithNibName:#"ReferFriendVC" bundle:nil];
// [self presentPopupViewController:okpopup animationType:MJPopupViewAnimationSlideBottomTop];
UIPopoverController *popup;
MyActivityItemProvider *message = [[MyActivityItemProvider alloc] init];
NSArray *activityItems;
UIImage *myImage=[UIImage imageNamed:#"3.png"];
activityItems = #[message, myImage];
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = #[
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeAirDrop,
UIActivityTypeAddToReadingList,
UIActivityTypeCopyToPasteboard,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePrint,
UIActivityTypePostToFlickr,UIActivityTypePostToTencentWeibo // Whatever you want to exclude
];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")){
activityViewController.popoverPresentationController.sourceView =
self.view;
}
if(isiPhone)
{
[self presentViewController:activityViewController animated:YES completion:nil];
}
else{
popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[popup presentPopoverFromRect:CGRectMake(0, screenheight, 768, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
[activityViewController setCompletionWithItemsHandler:^(NSString *act, BOOL completed, NSArray *returnedItems, NSError *activityError)
{
NSLog(#"act type %#",act);
NSString *ServiceMsg = nil;
if ( [act isEqualToString:UIActivityTypeMail] )
ServiceMsg = #"Mail sent";
NSLog(#"mail sent");
if ( [act isEqualToString:UIActivityTypeAssignToContact] )
ServiceMsg = #"Post on twitter, ok!";
if ( [act isEqualToString:UIActivityTypePostToFacebook] )
ServiceMsg = #"Post on facebook, ok!";
[popup dismissPopoverAnimated:YES];
}];
And in myActivityItemProvide.h
#import "MyActivityItemProvider.h"
#implementation MyActivityItemProvider
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
NSLog(#"mail method called ");
//
if([AppDelegate NetworkRechability])
{
// FrindListVC *leavefeed=[[FrindListVC alloc]initWithNibName:#"FrindListVC" bundle:nil];
// [self.navigationController pushViewController:leavefeed animated:YES];
FBSDKAppInviteContent *content1 =[[FBSDKAppInviteContent alloc] init];
content1.appLinkURL = [NSURL URLWithString:#"https://fb.me/4931252562362626805"];
//optionally set previewImageURL
content1.appInvitePreviewImageURL = [NSURL URLWithString:#"http://files.parsdrterfsdfetfss.com/79580e8563-55656cc-456455f2-a20f-7f69e783b14d/tfss-f9e2626e-dfsdfsfsdfsdf519c-4ca3-ae47-015ffeaad0f7-fbinvite-01.png"];
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content1
delegate:self];
// [[[self parentViewController] parentViewController] presentViewController:activityViewController animated:YES completion:nil];
// activityViewController.view.hidden=YES;
}
else
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Internet Not Available" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
[SVProgressHUD dismiss];
}
}
return #"No provider";
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"error %#",error);
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)result
{
// NSLog(#"result %#",result);
}
- (id) activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { return #""; }
#end
You can exclude or block to open default Facebook sharing in UIActivityViewController using below code:
activityViewController.excludedActivityTypes = [UIActivityTypePostToFacebook]

Is there a Firebase iOS Simple Login example for Twitter?

I'm having trouble coming up with a solution to the following from the Simple Login iOS quick start:
Since it is possible for a device to have more than one Twitter account attached, you will need to provide a block which can be used to determine which account to log in. Replace "[yourApp selectUserName:usernames]" below with your own code to choose from the list of usernames.
This is the code that is provided:
[authClient loginToTwitterAppWithId:#"YOUR_CONSUMER_KEY"
multipleAccountsHandler:^int(NSArray *usernames) {
// If you do not wish to authenticate with any of these usernames, return NSNotFound.
return [yourApp selectUserName:usernames];
} withCompletionBlock:^(NSError *error, FAUser *user) {
if (error != nil) {
// There was an error authenticating
} else {
// We have an authenticated Twitter user
}
}];
Would a UIActionSheet that allows the user to pick which account to use be best? How would that be done?
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
For login:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
// Request access from the user to use their Twitter accounts.
// [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
//NSLog(#"%#",error);
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
//NSLog(#"%#",accountsArray);
twitterAccountsArray=[accountsArray mutableCopy];
if ([twitterAccountsArray count] > 0){
sheet = [[UIActionSheet alloc] initWithTitle:#"Choose an Account" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for (ACAccount *acct in twitterAccountsArray) {
[sheet addButtonWithTitle:acct.username];
}
}
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
//NSLog(#"%#",error);
if (![error.localizedDescription isEqual:[NSNull null]] &&[error.localizedDescription isEqualToString:#"No access plugin was found that supports the account type com.apple.twitter"]) {
}
else
[Utility showAlertWithString:#"We could not find any Twitter account on the device"];
});
}
}];
It will open an action sheet which will show you the list of accounts your device has.
For posting :
There must be at least one valid twitter account added on your iPhone device.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
NSString *initialText=#"Text to be posted";
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
switch(result) {
// This means the user cancelled without sending the Tweet
case SLComposeViewControllerResultCancelled:{
}
break;
case SLComposeViewControllerResultDone:{
}
break;
}
};
[tweetSheet setInitialText:initialText];
if (initialText) {
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
I've found a nice example of how to do this with Awesome Chat's code. It uses a UIActionSheet like I was attempting to.
//-------------------------------------------------------------------------------------------------------------------------------------------------
- (IBAction)actionTwitter:(id)sender
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
[ProgressHUD show:#"In progress..." Interaction:NO];
//---------------------------------------------------------------------------------------------------------------------------------------------
selected = 0;
//---------------------------------------------------------------------------------------------------------------------------------------------
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
//---------------------------------------------------------------------------------------------------------------------------------------------
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
accounts = [account accountsWithAccountType:accountType];
//-------------------------------------------------------------------------------------------------------------------------------------
if ([accounts count] == 0)
[self performSelectorOnMainThread:#selector(showError:) withObject:#"No Twitter account was found" waitUntilDone:NO];
//-------------------------------------------------------------------------------------------------------------------------------------
if ([accounts count] == 1) [self performSelectorOnMainThread:#selector(loginTwitter) withObject:nil waitUntilDone:NO];
if ([accounts count] >= 2) [self performSelectorOnMainThread:#selector(selectTwitter) withObject:nil waitUntilDone:NO];
}
else [self performSelectorOnMainThread:#selector(showError:) withObject:#"Access to Twitter account was not granted" waitUntilDone:NO];
}];
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)selectTwitter
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#"Choose Twitter account" delegate:self cancelButtonTitle:nil
destructiveButtonTitle:nil otherButtonTitles:nil];
//---------------------------------------------------------------------------------------------------------------------------------------------
for (NSInteger i=0; i<[accounts count]; i++)
{
ACAccount *account = [accounts objectAtIndex:i];
[action addButtonWithTitle:account.username];
}
//---------------------------------------------------------------------------------------------------------------------------------------------
[action addButtonWithTitle:#"Cancel"];
action.cancelButtonIndex = accounts.count;
[action showInView:self.view];
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
if (buttonIndex != actionSheet.cancelButtonIndex)
{
selected = buttonIndex;
[self loginTwitter];
}
else [ProgressHUD dismiss];
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)loginTwitter
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
Firebase *ref = [[Firebase alloc] initWithUrl:FIREBASE];
FirebaseSimpleLogin *authClient = [[FirebaseSimpleLogin alloc] initWithRef:ref];
//---------------------------------------------------------------------------------------------------------------------------------------------
[authClient loginToTwitterAppWithId:TWITTER_KEY multipleAccountsHandler:^int(NSArray *usernames)
{
return (int) selected;
}
withCompletionBlock:^(NSError *error, FAUser *user)
{
if (error == nil)
{
if (user != nil) [delegate didFinishLogin:ParseUserData(user.thirdPartyUserData)];
[self dismissViewControllerAnimated:YES completion:^{ [ProgressHUD dismiss]; }];
}
else
{
NSString *message = [error.userInfo valueForKey:#"NSLocalizedDescription"];
[self performSelectorOnMainThread:#selector(showError:) withObject:message waitUntilDone:NO];
}
}];
}

I want to use identifiers in .m in other .m (implementation file import) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
On cameraviewcontrolle.mr I take a picture or movie using UIImagePickerController. On completion, I call back to aanvraagviewcontroller.m.
I want to save the the picture by tapping on send button.
My question comes to this I think, how can I import .m file or take the picture/movie to aanvraagviewcontroller.m (I use Parse.com to save my PFObjects)?
This is cameraviewcontroller.m
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
// A photo was taken/selected!
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the image!
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
}
}
else {
// A video was taken/selected!
self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the video!
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
}
}
}
[self uploadMessage];
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popToRootViewControllerAnimated:YES];}
- (void)uploadMessage {
NSData *fileData;
NSString *fileName;
NSString *fileType;
if (self.image != nil) {
UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
fileData = UIImagePNGRepresentation(newImage);
fileName = #"image.png";
fileType = #"image";
}
else {
fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
fileName = #"video.mov";
fileType = #"video";
}
PFFile *file = [PFFile fileWithName:fileName data:fileData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"An error occurred!"
message:#"Please try sending your message again."
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {// onderdeelAanvraag[#"file"] = file;
// onderdeelAanvraag[#"fileType"] = fileType;
// onderdeelAanvraag[#"recipientIDs"] = self.recipients;
//
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"An error occurred!"
message:#"Please try sending your message again."
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {
// Everything was successful!
[self reset];
}
// }];
}
}];
}
- (void)reset {
self.image = nil;
self.videoFilePath = nil;
[self.recipients removeAllObjects];
}
- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {
CGSize newSize = CGSizeMake(width, height);
CGRect newRectangle = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(newSize);
[self.image drawInRect:newRectangle];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizedImage;
}
This is aanvraagviewcontroller.m (when send button is pressed, i want to save the picture/movie here);
- (IBAction)verstuurAanvraag:(id)sender {
NSString *onderdeelOmschrijving = self.onderdeelOmschrijvingField.text ;
NSString *autoOmschrijving = self.autoOmschrijvingField.text ;
if ([onderdeelOmschrijving length] == 0 ||
[autoOmschrijving length] == 0)
{
UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:#"Leeg veld" message:#"Vul de lege velden in" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
}
else {
PFObject *onderdeelAanvraag = [PFObject objectWithClassName:#"Aanvragen"];
[onderdeelAanvraag setObject:[PFUser currentUser] forKey:#"Aanvrager"];
onderdeelAanvraag[#"OnderdeelOmschrijving"] = onderdeelOmschrijving;
onderdeelAanvraag[#"AutoOmschrijving"] = autoOmschrijving;
NSDate *date = [NSDate date];
onderdeelAanvraag[#"Datum"] =date;
onderdeelAanvraag[#"file"] = file;
onderdeelAanvraag[#"fileType"] = fileType;
onderdeelAanvraag[#"recipientIDs"] = self.recipients;
// Get random number between 0 and 999999
int nummer = arc4random() % 100000;
NSLog(#"nieuw nummer %d", nummer);
[onderdeelAanvraag setObject:[NSNumber numberWithInt:nummer] forKey:#"AanvraagNummer"];
[onderdeelAanvraag saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry!" message: [error.userInfo objectForKey:#"error"] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else {
[self performSegueWithIdentifier:#"showRecipients" sender:self];
}
}];
}
}
I SOLVED PASSING UITEXTFIELD TEXT BY THIS ;
I solved passing textfield data passing with the segue method like here ;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"showRecipients"]){
OntvangersViewController *controller;
controller = [segue destinationViewController];
controller.onderdeelOmschrijvingField = self.onderdeelOmschrijvingField;
controller.autoOmschrijvingField = self.autoOmschrijvingField;
controller.image = self.image;
controller.videoFilePath = self.videoFilePath;
NSLog(#"videofilepath %#", self.videoFilePath);
controller.recipients = self.recipients;
}
}
Your question is muddled and confused.
The code in a .m file is not shared with other .m files.
The whole point of the C .h header file is that the header file can be shared, while the implementation (.c, or .m for Objective C) is private, and not shared.
If you want a value to be visible to another class, or another object of the same class, you should define a property in the header file.
If you want to pass a value from one view controller to another, this topic has been covered Ad nauseam here and on other forums. There are at least 2 comments on your post pointing you to other threads covering the topic.

How to know which icon is clicked in UIActivityViewController before activityController setCompletionHandleris called?

How to know which icon is clicked in UIActivityViewController before activityController setCompletionHandler:^(NSString *activityType, BOOL completed) is called ?
I want to share different text for sharing with twitter and facebook.
-(IBAction)btnSharePressedFromOffersDetail:(id)sender
{
NSString *posturl= #"facebook or twitter";
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]init];
NSArray *Itemsarray=#[posturl,printData];
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:Itemsarray applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Thanks for sharing!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
}
}];
}
If your goal is to use a different text for Twitter or Facebook, it's the responsability of your shared Model who implement the UIActivityItemSource protocol.
- (id) activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if([activityType isEqualToString:UIActivityTypePostToFacebook]) return #"Facebook text";
else if([activityType UIActivityTypePostToTwitter]) return #"Twitter text";
else return #"Default text";
}
You can go with link given below, there is tutorial which might helps you.
https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/
and http://nshipster.com/uiactivityviewcontroller/

What should i do, when user cant send message to twitter

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

Resources