Issue posting file url using UIActivityViewController - facebook

I am trying to share my app document (file url ) using UIActivityViewController. When activityviewcontroller pop up (testing on iPad device), I get only iMessage and Mail options. I DO NOT GET OTHER OPTIONS like Facebook, Twitter, Copy, Print, etc. Why? Please help me. I need Facebook, twitter options also. File type which I am sharing using NSURL is .txt
Note: I am already signed in to my Facebook, twitter account in iOS settings.
Source code which I am using:
NSURL *url = [NSURL fileURLWithPath:self.path];
NSArray *objectsToShare = #[url];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[APP_VIEW_CONTROLLER presentViewController:activityViewController animated:YES completion:nil];
}
else
{
if (![self.activityPopover isPopoverVisible]) {
self.activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.activityPopover presentPopoverFromRect:pathViewController.pathViewWrapper.pathView.bounds inView:pathViewController.pathViewWrapper.pathView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
//Dismiss if the button is tapped while pop over is visible
[self.activityPopover dismissPopoverAnimated:YES];
}
}

It is indeed mysterious what shows up in the UIActivityViewController. Regarding Facebook and Twitter 1) it likely needs to be an http or https URL (not a file URL), 2) make sure those services are configured on the simulator or iOS device you're using.

For posting to Facebook. The file can be a file stored on the device locally. However, it needs to be converted to MP4. By default, videos taken by device camera are .MOV files. Once you convert to .MP4 if you provide the local file location, UIActivityController will share to Facebook.
I got FB to work, I'm working on Twitter now. I will edit my answer and provide details when I'm done.
Here is some code:
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
activityController.excludedActivityTypes = #[ UIActivityTypeMail,
UIActivityTypeAssignToContact,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAddToReadingList,
UIActivityTypeSaveToCameraRoll];
NSMutableArray *items = [[[Engine sharedEngine].thingsManager getSharingMessageForThingWithId:self.thingId
categoryName:self.category.name
brandName:self.brand.name
andText:message
isVideo:([self.videoURL.absoluteString length] > 0 ? YES : NO)] mutableCopy];
if ([self.videoURL.absoluteString length] > 0) {
//Get the .mp4 converted video url
if (self.awsManager == nil) {
self.awsManager = [[AWSManager alloc] init];
}
NSURL *mp4Url = [self.awsManager convertVideoToMP4:self.videoURL];
//[items addObject:self.videoAmazonPath];
[items addObject:mp4Url];
} else {
[items addObject:self.image];
}
Hope this helps.

Related

iPhone:Error occurs while uploading image on twitter using sharekit

I am using sharekit to upload the image on twitter.
I have set keys and callback URL perfectly.
But after entering my login and password credentials
to upload image on twitter I got following error message.
"There was a problem requesting access from Twitter."
Earlier before few months in the same app I was able to upload
the image with same code.
But right now I am facing the problem
can you tell me what is the exact problem
thanks in advance.
There is some changes occur in share kit. To resolve this issue. You have to change some piece of lines in SHKTwitter.mfile under this method:
- (void)tokenAccessModifyRequest:(OAMutableURLRequest *)oRequest
For detail info follow this link & make changes according to this link & then check:
https://github.com/SteveLeviathan/ShareKit/commit/7aab77655c1cbb1bf79092fcb3bb24dd80ab6380
UPDATE:
Replace your this method with my & then check:
- (void)tokenAccessModifyRequest:(OAMutableURLRequest *)oRequest
{
if (xAuth)
{
NSDictionary *formValues = [pendingForm formValues];
OARequestParameter *username = [[[OARequestParameter alloc] initWithName:#"x_auth_username"
value:[formValues objectForKey:#"username"]] autorelease];
OARequestParameter *password = [[[OARequestParameter alloc] initWithName:#"x_auth_password"
value:[formValues objectForKey:#"password"]] autorelease];
OARequestParameter *mode = [[[OARequestParameter alloc] initWithName:#"x_auth_mode"
value:#"client_auth"] autorelease];
[oRequest setParameters:[NSArray arrayWithObjects:username, password, mode, nil]];
}
else {
if (self.pendingAction == SHKPendingRefreshToken)
{
if (accessToken.sessionHandle != nil)
[oRequest setOAuthParameterName:#"oauth_session_handle" withValue:accessToken.sessionHandle];
}
else
[oRequest setOAuthParameterName:#"oauth_verifier" withValue:[authorizeResponseQueryVars objectForKey:#"oauth_verifier"]];
}
}
You can switch to ShareKit 2 - it is being updated frequently.

How to add different text to UIActivityViewController objects

I have implemented a UIActivityViewController, for sharing some information. In this case I have a question: Is it possible to make a different text between the facebook sharing/twitter sharing/ or mail sharing? That the text which is set is different from the others...
A good UIActivityViewController tutorial would be very useful.
My code at the time is, for displaying text and image:
NSString *text = #"Lime Cat";
UIImage *image = [UIImage imageNamed:#"MyApp Icon 512x512.png"];
NSArray *items = [NSArray arrayWithObjects:text,image , nil];
But how can I manage it that the NSString is just for the mail, and make a seperate NSString for the facebook share option?
Any suggestions?
Thanks.
you can go to the link bellow, there is a tutorial that can help you :
https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/
You can have your class conform to the UIActivityItemSource protocol and implement activityViewController:itemForActivityType:. The activityType will be FB, Twitter, Messages app, etc, so you can do a switch on it and return a different object based on the activity.
-(void)ShareImageandText:(UIButton *)sender
{
NSString *texttoshare =#"http://qrs.ly/l851gh4";
UIImage *image = [UIImage imageNamed:#"default"];
NSString *noteStr = [NSString stringWithFormat:#"Please follow this link below to install the Freedom.desi application on your IPhone. %#",texttoshare];
NSURL *url = [NSURL URLWithString:texttoshare];
NSArray *activityItems = #[noteStr,image];
NSLog(#"this %#",activityItems);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr,image] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
//if iPad
else {
// Change Rect to position Popover
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[noteStr, url] applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self shareText:noteStr
andImage:image andUrl:nil];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

Photo Posting in Twitter in iOS5

I am new one to twitter integration in iOS5.
I need to post photos in twitter coming from services.
I have searched many and also practiced sample tutorials on this.
I am getting only photo URL. I need to post photo.
Can anyone help me regarding this?
Thanks in advance.
First you need to save the images and then you can post saved image to twitter
self.shareImg.image = [UIImage imageNamed:#"Your Saved image"];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
NSString *str = [NSString stringWithFormat:#"I created this photo http://%#", iTune];
// Optional: set an image, url and initial text
[twitter addImage:self.shareImg.image];
[twitter setInitialText:[NSString stringWithFormat:#"I created this photo using USC Project Trojan App:http://uslofphoto.com. Download http://%#", iTune]];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}

MPNowPlayingInfoCenter defaultCenter will not update or retrieve information

I'm working to update the MPNowPlayingInfoCenter and having a bit of trouble. I've tried quite a bit to the point where I'm at a loss. The following is my code:
self.audioPlayer.allowsAirPlay = NO;
Class playingInfoCenter = NSClassFromString(#"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:#"series_placeholder"]];
[songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
[songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
[songInfo setObject:#"NCC" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
This isn't working, I've also tried:
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
In an attempt to get it to remove the existing information from the iPod app (or whatever may have info there). In addition, just to see if I could find out the problem, I've tried retrieving the current information on app launch:
NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
NSString *author = [info valueForKey:MPMediaItemPropertyArtist];
NSLog(#"Currently playing: %# // %#", title, author);
and I get Currently playing: (null) // (null)
I've researched this quite a bit and the following articles explain it pretty thoroughly, however, I am still unable to get this working properly. Am I missing something? Would there be anything interfering with this? Is this a service something my app needs to register to access (didn't see this in any docs)?
Apple's Docs
Change lock screen background audio controls
Now playing info ignored
I finally figured out the problem, I was not prompting my app to receive remote control events, simply adding this line fixed the problem:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
I use the code below and it always works. I'm also using MPMoviePlayer like you. Have you checked whether NSClassFromString(#"MPNowPlayingInfoCenter") ever actually returns YES? Have you set you app play audio in background key in your plist?
- (void) loadMPInformation
{
NSDictionary *mpInfo;
if([savedTrack.belongingAlbum.hasAlbumArt boolValue] == NO){
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, nil];
} else {
UIImage *artImage = [UIImage imageWithData:savedTrack.belongingAlbum.art];
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:artImage];
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, artwork, MPMediaItemPropertyArtwork, nil];
}
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = mpInfo;
}

Is it possible to check if a user has a twitter account in the built-in twitter app of iOS 5?

iOS 5 has deep twitter integration. How can I check if the user has an account in the built-in twitter app (meaning he uses it), and then do a UIApplication openURL: to trigger following a user or pre-composing a tweet?
One of the new features for developers in the iOS 5 SDK is support for
the Twitter API. Apple has made it easy for developers to add Twitter
support to their apps and to allow users to easily control whether or
not an app has access to post to their Twitter account.
According to this site it is possible. How's that Twitter Framework called?
Try this:
- (void)tweetButtonPressed:(id)sender
{
Class tweetComposer = NSClassFromString(#"TWTweetComposeViewController");
if( tweetComposer != nil ) {
if( [TWTweetComposeViewController canSendTweet] ) {
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController setInitialText:#"This is a test."]; // set your initial text
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if( result == TWTweetComposeViewControllerResultDone )
{
// user is done with composing
}
else if( result == TWTweetComposeViewControllerResultCancelled )
{
// user has cancelled composing
}
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:tweetViewController animated:YES completion:nil];
}
else {
// The user has no account setup
}
}
else {
// no Twitter integration
}
}
For the first part of your question...
ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
This is how we're doing it in DETweetComposeViewController.
You could try something like:
BOOL didOpenTwitterApp = [UIApplication openURL:[NSURL URLWithString:#"twitter:///user?screen_name=senior"]];
This will return false if the app can't open the official Twitter app.
If you just want to create a new Tweet, use the native API