We've the following method to share content in the application. For each content we share:
Text
Image
URL
+ (void) generalShare:(NSString *) text withEntity:(SMEntity *) theEntity onView:(UIViewController*) theViewController withImage:(UIImage *) image completion:(void (^)(void))completion
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:templateURL
, [SMSocialManager getAction:theEntity]
, [theEntity getId]]];
NSArray *sharingItems = #[text, url, image];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[activityController setValue:text forKey:#"subject"];
[UINavigationBar appearance].barStyle = UIBarStyleBlack;
[UINavigationBar appearance].translucent = NO;
[UINavigationBar appearance].barTintColor = UIColorFromRGB(SMPrimaryColor);
[theViewController presentViewController:activityController animated:YES completion:^{
return completion();
}];
}
Until a few time it works perfectly, a few time ago the text was missing when you try to share in facebook (based on the new policy) but just a days ago the image, is also missing, and just the URL is included.
Any suggestions?
I could figure out generating an ad-hoc solution for each destination social network, but find a way to solve with an standard solution could be better approach.
Thank you!
It seams facebook and instagram removed the caption from the integration, and I don't know why but with facebook also the image is not working anymore.
Related
I am using UIActivityViewController in my new app for Facebook Share Option.
But if the user not login to the device, it dont working.. When select setting, Login page not appearing..
IActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self presentViewController:activityVC animated:TRUE completion:nil];
What can i do on this..? Is that the Problem of my code or a Common Error..?
iOS 6 introduced both the UIActivityViewController class and Social Framework, both of which may be used to integrate Twitter, Facebook and Sina Weibo functionality into iOS 6 applications. For general purpose requirements, the UIActivityViewController and SLComposeViewController classes provide an easy to implement path to social network integration.
UIActivityViewController *activityController =[[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
self presentViewController:activityController animated:YES completion:nil];
In order to use the SLComposeViewController class, a number of steps should be performed in sequence. Firstly, the application may optionally check to verify whether a message can be sent to the specified social network service. This essentially equates to checking if a valid social network account has been configured on the device and is achieved using the isAvailableForServiceType: class method, passing through as an argument the type of service required from the following options:
SLServiceTypeFacebook
SLServiceTypeTwitter
SLServiceTypeSinaWeibo
this is how you start ActivityIndicatorView with Loading lable
UIActivityIndicatorView *tempSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
lable =[[UILabel alloc]init];
lable.center = self.view.center;
lable.text = #"Loading...";
lable.hidden=NO;
lable.backgroundColor = [UIColor clearColor];
lable.textColor = [UIColor blackColor];
[lable sizeToFit];
lable.center = CGPointMake(160, 255);
tempSpinner.center = self.view.center;
[self.view addSubview:tempSpinner];
[self.view addSubview:lable];
start where ever you want like this
[tempSpinner startAnimating];
stop it like this where ever you want
[tempSpinner stopAnimating];
hide unhide loading label as per requirement
I try to share a web page url with NSSharingServicePicker to Facebook, but it appears on my FB wall not as a web page url(with description and so on), but just like a link.
My code is very simple.
- (IBAction)share:(id)sender
{
NSURL* url = [NSURL URLWithString:#"http://itunes.apple.com/us/app/travel-route-planner/id504536611"];
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObjects:url, nil]];
sharingServicePicker.delegate = self;
[sharingServicePicker showRelativeToRect:[shareButton bounds]
ofView:shareButton
preferredEdge:NSMinYEdge];
}
I know it could be done.
Safari shares web pages the way i need.
I took a look at the source code on the website you're trying to share, and ran it through the Facebook Object Debugger. Facebook is pretty picky when it comes to the defined protocol, so I'd recommend changing your URL from http:// to https:// as the secure URL is what iTunes has decided to set as their og:url property. See here:
I found the answer on Apple Dev forums.
You need to add image to NSURL using following NSSharingServiceDelegate methods
- (NSRect) sharingService: (NSSharingService *) sharingService
sourceFrameOnScreenForShareItem: (id<NSPasteboardWriting>) item
{
if([item isKindOfClass: [NSURL class]])
{
//return a rect from where the image will fly
return NSZeroRect;
}
return NSZeroRect;
}
- (NSImage *) sharingService: (NSSharingService *) sharingService
transitionImageForShareItem: (id <NSPasteboardWriting>) item
contentRect: (NSRect *) contentRect
{
if([item isKindOfClass: [NSURL class]])
{
return [NSImage imageNamed:#"image.png"];
}
return nil;
}
don't forget to set the delegate for your NSSharingService
- (id < NSSharingServiceDelegate >)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
{
return self;
}
Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.
In my application i get the links of video from server in UITableview .all these link are store on Sever in Textfile,i get all these link from sever one by one and assign each to cell in UITableview.all these i done succefully but i want when i click on any cell in UITableview its play the video in next view.here is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
nextview *dvController = [[nextview alloc] initWithNibName:#"nextview" bundle:nil];
[self presentModalViewController:dvController animated:YES];
strFile = [Listdata objectAtIndex:indexPath.row];
NSLog(#"test=%#",strFile);
[dvController release];
}
and in next view i assign the link which i store in "strFile" to MPMoviePlayerController here is my code.
-(void)viewDidAppear:(BOOL)animated
{
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.view.frame = CGRectMake(0, 0,900, 700);
[self.view addSubview:myplayer.view];
[myplayer play];
}
In NSlog i see the link but its not play in MPMoviePlayerController.Any one can guide me that what mistake i make.thanx in advance.
#prince : can u tell me what url you are getting in NSLog?? i think u're mistaken in getting the url.
we can get url either by
url = [NSURL fileURLWithPath:strUrl];
else
url = [NSURL URLWithString:strUrl];
try it out once.
You probably shouldn't be setting the frame and adding to the subview, You may be confused with MPMoviePlayerViewController. Try this...
-(void)viewDidAppear:(BOOL)animated {
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.scalingMode = MPMovieScalingModeAspectFill;
[myplayer play];
}
EDIT disregard my code, you can't directly play a YouTube video in MPMoviePlayerController. Check this Post instead Play YouTube videos with MPMoviePlayerController instead of UIWebView
to youtube video play inside app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. try this link:
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.
I am going to ask that one question that perhaps has been already asked a million times.
I am making an app for iPad and want to give users the ability to multi-select images from their photo-library. I already have a working code for user to select one image at a time. (not what I need)
I have already downloaded and looked into ELC image picker sample code but that code is not compatible with iOS 5 or Xcode 4. i.e. it has ARC and compile problems left and right, its using release and dealloc all over the place.
I am just frustrated that apple hasn't already created a built in-api for us developers for this most commonly requested functionality in most of our iPhone/ipad apps. (not one but multi-select pics)
Is there any other sample code available? Trust me, I have been googling for a while.
Ok, I have this figured out. The problem with Assets Library is that it gives you all the GEO data of the image. What that means for your users using your app is that they will get a prompt saying that your app is trying to access their location. Infact all you are trying to do is let them choose multiple images from their photo-album. Most users will be turned off thinking its a piracy issue. The best approach is to use apples api of imagePickerController. I know it lets you choose one pic at a time but if you add the following code, it will let you choose multiple pictures.
The way I am doing is let the users keep selecting pictures they want, keep saving those files in the app documents directory, till they hit the done button. See here my sample code and hopefully it will save you the pain of going through Assets Library
-(IBAction)selectExitingPicture
{
//Specially for fing iPAD
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popoverController presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 300.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
//Done button on top
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
//NSLog(#"Inside navigationController ...");
if (!doneButton)
{
doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleDone
target:self action:#selector(saveImagesDone:)];
}
viewController.navigationItem.rightBarButtonItem = doneButton;
}
- (IBAction)saveImagesDone:(id)sender
{
//NSLog(#"saveImagesDone ...");
[popoverController dismissPopoverAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
//DONT DISMISS
//[picker dismissModalViewControllerAnimated:YES];
//[popoverController dismissPopoverAnimated:YES];
IMAGE_COUNTER = IMAGE_COUNTER + 1;
imageView.image = image;
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
// Give a name to the file
NSString* incrementedImgStr = [NSString stringWithFormat: #"UserCustomPotraitPic%d.jpg", IMAGE_COUNTER];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr];
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
//Now use this code to get to user selected pictures. Call it from wherever you want in your code
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSString* dataFile = [documentsPath stringByAppendingPathComponent:#"UserCustomPotraitPic1.jpg"];
NSData *potraitImgData = [NSData dataWithContentsOfFile:dataFile];
backgroundImagePotrait = [UIImage imageWithData:potraitImgData];
Apple has provided api for this. It is called ALAssetsLibrary.
Using this you can select multiple images/ videos and other operations that you do using photo application on iOS device.
As in documentation Apple says:
Assets Library Framework
Introduced in iOS 4.0, the Assets Library framework
(AssetsLibrary.framework) provides a query-based interface for
retrieving photos and videos from the user’s device. Using this
framework, you can access the same assets that are normally managed by
the Photos application, including items in the user’s saved photos
album and any photos and videos that were imported onto the device.
You can also save new photos and videos back to the user’s saved
photos album.
Here are few links where you can learn more. Now to use it you can search for ALAssetsLibrary.
Assets Library Reference
http://www.fiveminutes.eu/accessing-photo-library-using-assets-library-framework-on-iphone/
Starting with iOS 14, multiple image selection is now supported in the new Photos picker. Here is sample code from Apple: Selecting Photos and Videos in iOS.
I use ALAssetsLibrary and rolled my own UI. The problem with UIImagePickerController is that it says you are supposed to dismiss the view controller in the didFinishPickingMediaWithInfo callback, so hacking multiple selection by not dismissing may run into problems. I know I did when I first tried it. I can't recall exactly what went wrong, but there were cases where UIImagePickerController simply stopped working if I didn't dismiss it like the docs say.