Is there any built-in api/code for Xcode that allow the app to detect what other social media apps installed in the iphone/ipad/ipod touch to populate out the sharing features?
I was told that Android has such capability, so does iOS have it too?
Twitter integration is built into iOS 5, check this link http://developer.apple.com/library/ios/documentation/Twitter/Reference/TWTweetSheetViewControllerClassRef/Reference/Reference.html
For Facebook you need to use the Facebook SDK, check here http://developers.facebook.com/docs/reference/iossdk/
Alternatively you could try ShareKit... http://getsharekit.com/
Or GetSocialize...
http://www.GetSocialize.com/
Both of these offer drop in functionality.
- (IBAction) shareHasTapped: (id)sender {
NSString *texttoshare = #"text to share";
// UIImage *imagetoshare = [UIImage imageNamed:#"beck.png"];
NSArray *activityItems = #[texttoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes =#[UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
Share Image Social Network Using UIActivityViewController:
-(void)shareimage
{
NSArray *objectsToShare = #[_s_image];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
avc.excludedActivityTypes=#[UIActivityTypePostToTwitter];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:avc animated:YES completion:nil];
}
else
{
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:avc];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Related
I have read the UIPopoverController docs and more then 10 stackoverflow solutions which none work in iOS 8.0.2 ipad device.
THE GOAL:
I want to present a sharing view which when clicked outside dissmisses.
THE PROBLEM:
The code works fine below iOS 8.0.
THE CODE (tried many versions...):
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
self.act = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.act presentPopoverFromRect:CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, self.view.bounds.size.width/2, self.view.bounds.size.width/2) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
self.act.delegate = self;
I have added the :
UIPopoverControllerDelegate
WHAT I HAVE TRIED:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
As soon that the
UIPopoverController
is presented the view losses focus and doesn't register touches. Therefore, I can't handle touches outside the self.act rect space in order to force a dissmisal.
also...
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
UIPopoverPresentationController *presentationController = [activityViewController popoverPresentationController];
presentationController.sourceView = self.view; // if button or change to self.view.
[self.parentViewController presentViewController:activityViewController animated:YES completion:nil];
and I tried to present the UIActivityViewController and UIPopoverController from the parent which didn't work aswell.
Please help, I lost half day on something this stupid which works on iOS 7.1 and not on iOS 8+ which is ridiculous and I still have no clue why.
I will try to add the cancel button which has also disappeared in iOS8+.
UPDATE 1:
Adding a UIButton inside a UIBarButtonItem didn't help...
UIButton *control = (UIButton *) sender;
[control setFrame:CGRectMake(300, 300, 100, 100)];
[control setBackgroundColor:[UIColor redColor]];
UIBarButtonItem *barButtonItemView = [[UIBarButtonItem alloc] init];
[barButtonItemView setCustomView:control];
[self.popup presentPopoverFromBarButtonItem:barButtonItemView permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
UPDATE 2 - 19.12.2014. (iOS 7.1. - 8.1.2):
The accepted answer works on iOS 8.1. I had some errors with iOS 7.1. so I modified it to work for iOS 7.1. I have stated on which devices the code works in the comments below the answer.
// publish - sharing
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSLog(#" SHARING - 1 - ");
[self presentViewController:activityViewController animated:YES completion:^{}];
}
else
{
// Change Rect to position Popover
NSLog(#" SHARING - 2 - ");
self.popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width * 3 / 5 ,
self.view.frame.size.width/2,
self.view.frame.size.width/10,
self.view.frame.size.width/10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
How about just add this.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
activityViewController.popoverPresentationController.sourceView = self.view;
I have an app. On a click on the button I want the screen of the app should be captured and MailComposer window should be opened and the image captured previously should get attached to it. The mail sent but there is no attached image file
plz help me.
thank in advance...,
My code is here....
MFMailComposeViewController *controller =[[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"Screen shot maker"];
[controller setMessageBody:#"Hi , <br/> This is Screen Shot Maker" isHTML:YES];
[controller addAttachmentData:[NSData dataWithContentsOfFile:#"myScreenShot.png"] mimeType:#"png" fileName:#"myScreenShot.png"];
if (controller)
[self presentModalViewController:controller animated:YES];
Use below code:
UIGraphicsBeginImageContext(self.view.bounds.size);
// [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller addAttachmentData:data mimeType:#"application/image" fileName:#"Test.png"];
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
controller.modalPresentationStyle = UIModalPresentationFormSheet;
}
else
{
controller.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self presentModalViewController:controller animated:YES];
Is it possible to use AirDrop in the iOS 7 SDK without UIActivityViewController? Right now I don't use UIActivityViewController but I want to include AirDrop as an option.
You need to add UIActivityViewController, then exclude everything but airdrop.
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
// Exclude all activities except AirDrop.
NSArray *excludedActivities = #[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
// Present the controller
[self presentViewController:controller animated:YES completion:nil];
I have this case where I am using a custom UITabBar in my application.
It is working great in ios4 on both device and simulator.
But running the same code using xcode 4.2 and ios5 sdk wont work, as the app is crashing when I am setting the view controllers of my custom tabBarController on this line:
tabBarController.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
Here is how I am creating the tabBar:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
tabBarController = [[MBCustomTabBarController alloc] init];
home=[[Home alloc] initWithNibName:#"Home" bundle:nil];
UINavigationController *nc1=[[UINavigationController alloc] initWithRootViewController:home];
live=[[Live alloc] initWithNibName:#"Live" bundle:nil];
UINavigationController *nc2=[[UINavigationController alloc] initWithRootViewController:live];
report=[[Report alloc] initWithNibName:#"Report" bundle:nil];
UINavigationController *nc3=[[UINavigationController alloc] initWithRootViewController:report];
//custom tabbar items
MBCustomTabBarItem *firstItem = [[MBCustomTabBarItem alloc] initWithTitle:#"headlines" image:[UIImage imageNamed:#"HOME-.png"] tag:0];
MBCustomTabBarItem *secondItem = [[MBCustomTabBarItem alloc] initWithTitle:#"live" image:[UIImage imageNamed:#"NEWS-.png"] tag:1];
MBCustomTabBarItem *thirdItem = [[MBCustomTabBarItem alloc] initWithTitle:#"report" image:[UIImage imageNamed:#"REPORT-.png"] tag:2];
[firstItem setImage:[UIImage imageNamed:#"HOME.png"] forState:UIControlStateSelected];
[secondItem setImage:[UIImage imageNamed:#"NEWS.png"] forState:UIControlStateSelected];
[thirdItem setImage:[UIImage imageNamed:#"REPORT.png"] forState:UIControlStateSelected];
nc1.tabBarItem=firstItem;
nc2.tabBarItem=secondItem;
nc3.tabBarItem=thirdItem;
[firstItem release];
[secondItem release];
[thirdItem release];
tabBarController.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
[nc1 release];
[nc2 release];
[nc3 release];
tabBarController.customTabBar.frame = CGRectMake(0, 480 - 49, 320, 49);
tabBarController.customTabBar.backgroundColor = [UIColor clearColor];
tabBarController.customTabBar.itemWidth = 320 / [self.tabBarController.viewControllers count];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
And here is a small working example.
Your help is highly appreciated.
Never mind, I've totally changed my approach and used this answer to build my custom tabBar. And it is working fine under ios5.
I tried to record a video.
The message I got is from the following code on the device:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
Any ideas? I think it should be really easy to take a video. When I start the "Camera" app of the phone I have the choice between video and picture. Shouldn't it be available for my app also?
The problem was the way I was trying to set the mode to video mode.
Instead of using this:
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
I changed it to this:
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
and it worked.
For Swift 3.0, you have to add below line to support both photo and video
import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
Add to above answers, as Micko mentioned, you need to add MobileCoreServices.framework in your project and ref it in your imagePickerController.
For those who want to have a switch under the toolbar in your image shooting view, just set the mediaTypes delegate as follows:
imagePC.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
Now, you can have both still image taking and video taking, enjoy!!!
Xcode 9 - Swift 4.x:
Take care about the order of these statements:
imagePickerController.mediaTypes = [kUTTypeMovie as String]
imagePickerController.cameraCaptureMode = .video
And you remember to add to info.plist:
And if you are working with Swift, then you will have to add MobileCoreServices.framework as well as the following Module where you are trying to record the video!
import MobileCoreServices
Then overall your code will something like this
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.Camera;
imag.cameraDevice = UIImagePickerControllerCameraDevice.Rear //or Front
imag.mediaTypes = [kUTTypeMovie];
self.presentViewController(imag, animated: true, completion: nil)
This method will opens the library of videos in my ipod 4.Not the video camera of my device.
Will someone tell me how to sort out from the problem ,I have tried the both ways described above.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
and
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
Thanks for your help.
enter code herePlease try this,this will opens the video camera
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *tmp_picker=[[UIImagePickerController alloc]init];
tmp_picker.sourceType=UIImagePickerControllerSourceTypeCamera;
tmp_picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
tmp_picker.delegate=self;
[self presentModalViewController:tmp_picker animated:YES];
[tmp_picker release];
NSLog(#"button index is %i",buttonIndex);
}