I was using the following code with iOS 6 SDK to implement UIActivityViewController:
-(IBAction)Share:(id)sender
{
NSArray *activityItems = #[self.title, urlString];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Successfully Shared" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
} else
{
UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Unable To Share" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objalert show];
objalert = nil;
}
}];
}
The above code in iOS 7 is giving me the following output:
Earlier there wasn't Facebook and Twitter in the share sheet but i signed into both both these apps in the Settings and Facebook and Twitter started appearing.
PROBLEM: Belo the line, there is only COPY and other like BOOKMARK, ADD TO READING LIST, ADD TO HOMESCREEN, PRINT and AirDrop buttons are not showing up. What can i do to bring these? Thanks!
UPDATE: I have added the print button by using one answer below, how can i add the rest?
Bookmark, Add To Reading List, and Add To Homescreen are only available in safari, unless you define them yourself. To add those buttons, you need to create an applicationActivities NSArray, populated with UIActivity objects for various services. You can pass this array into the initWithActivityItems:applicationActivities: UIActivityViewController method (you were passing nil for this parameter).
You should use UISimpleTextPrintFormatter to show PRINT:
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
initWithText:self.title];
NSArray *activityItems = #[self.title, printData];
Follow #Arkadiusz Holko and #Santa Claus answers to add another functionality.
You should use NSURL object instead of NSString when you want an element to be treated as a URL. Replace:
NSArray *activityItems = #[self.title, urlString];
with
NSArray *activityItems = #[self.title, [NSURL URLWithString:urlString]];
Then follow #Santa Claus's advice if you want elements other than Add to Reading List to be visible.
Related
In my application I send data to server and parse.
But I have to send image and you need to choose category.
When you don't choose category I show for user information.
But: how can I check if the user has filled in all the fields? In my app choose image and category?
This is my code with show error when you don't choose category and send action:
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Category 'All' is reserved" message:#"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
return;
}
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
Your change could be as simple as using an else statement...
- (IBAction)submitItem:(UIButton *)sender {
if ([category isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Category 'All' is reserved" message:#"You need to choose different category" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
return;
}
else {
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
///// send image to server
NSString *urlString = urlSaveFullImageToServer;
...
Personally I think a better approach is not to enable the "send" button until all of the data is complete.
Set the submit button enabled property to NO and then when the various pieces of information are entered (the image, the category) check to see if everything is complete - once it is, set enabled to YES
I am developing a photo sharing application on iOS that shares pictures on various social networks including Flickr. In order to authorise the app and to upload photos on a Flickr photo-stream I use FlickrKit.
After successfully authorising the app I try to post the selected picture with the following code:
UIImage *img = self.itemsToShare[currentItem];
NSDictionary *uploadArgs = #{#"title": #"Test Photo", #"description": #"A Test Photo via FlickrKitDemo", #"is_public": #"0", #"is_friend": #"0", #"is_family": #"0", #"hidden": #"2"};
self.uploadOp = [[FlickrKit sharedFlickrKit] uploadImage:img args:uploadArgs completion:^(NSString *imageID, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
} else {
NSString *msg = [NSString stringWithFormat:#"Uploaded image ID %#", imageID];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Done" message:msg delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
});
}];
My problem is that the following error occurs:
2014-07-02 10:16:23.710 myApp[805:3507] <?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="95" msg="SSL is required" />
</rsp>
Does anyone have an idea where do I set an SSL connection for FlickrKit?
Thank you very much,
Granit
During my research I saw that the Flickr API is now SSL-Only form June 27th 2014. The fix is to change upload URL in FKImageUploadNetworkOperation.m file to:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://up.flickr.com/services/upload/"]];
[request setHTTPMethod:#"POST"];
all you need to update is the URL, from HTTP to HTTPS:
https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=.............&photoset_id=...............&format=rest
worked for me!
Simply you need to replace http to https in flickr API, due to secure connection issue.
I have an application that i need to integrate with twitter login, for logging in via their twitter account. In the application we also have Twitter sharing option. Here i want to implement functionality to choose their account in which account they want to share the tweet. If user is logged in for only one account, then there should be provision to login to another account without logging out of existing logged-in account.
Well, this really compounds about 5 different topics in to one, and we can't write your entire app for you, but here are some helpful pointers.
When it comes to twitter, I use the STTwitter API (https://github.com/nst/STTwitter). What this does is takes all the twitter code, and dumbs it down for us less objective-c inclined programmers. The "README" file contains more information about what you'd be needing. You can find the developer tutorial at http://www.veasoftware.com/tutorials/2014/6/17/xcode-5-tutorial-ios-7-app-only-authentication-twitter-api-version-11. This also allows you to download the project to test, and copy and paste code from.
Youtube and Google are also great sources to find information. Right now your request is quite broad and encompases quite a few different aspects of twitter integration, work on them one at a time from the ground up.
====>Download Third Party Class FSHTwitterEngine.
{
[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:#"6XITOIDiXNajx7TQMKOh8qDxj" andSecret:#"w4F44ATueFsarNjGQ9WDdEudJCBJ8P0o5zeNON5bP9hIKhGls6"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];
[[FHSTwitterEngine sharedEngine]loadAccessToken];
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
[self performSelector:#selector(TwitterPostMessage) withObject:nil afterDelay:1.0];
}];
[self presentViewController:loginController animated:YES completion:nil];
}
-(void)TwitterPostMessage
{
UIImage *aimg = [UIImage imageNamed:#"mark"];
// [[FHSTwitterEngine sharedEngine]postTweet:#"Hepp adsfihdf sdfhihdsfh" withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
#autoreleasepool {
//NSString *tweet = [alertView textFieldAtIndex:0].text;
// id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Post of image"];
id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Hi Successfully Post Twitter..." withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *title = nil;
NSString *message = nil;
if ([returned isKindOfClass:[NSError class]])
{
NSError *error = (NSError *)returned;
title = [NSString stringWithFormat:#"Error %d",error.code];
message = error.localizedDescription;
} else {
NSLog(#"%#",returned);
title = #"Tweet Posted";
message = #"Post of image";
}
dispatch_sync(dispatch_get_main_queue(), ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
}
});
}
});
}
EDIT: The error is with the data structures that are being used during PDF generation. I'll be able to debug it once I can get a copy of OSX that supports iOS7. Thanks for all the help everyone!
At work I have Mac dedicated to working on iOS 6 apps. So far it hasn't been possible to update to a newer version of OSX so my version of XCode can't be upgraded to support iOS7 naturally. So long story short I can't debug iOS7 apps, so I am not sure why the app is crashing.
I have a UIActionSheet. I used to be using one with those completion blocks but was trying to debug so I have stripped everything away to just the basic barebones and it still crashes when I click on the button.
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil ];
[actionSheet showFromBarButtonItem:sender animated:YES];
That's just sitting on the end of a PDF generation method.
Any ideas? I've been researching this all afternoon and I haven't found any reason why it would stop working like this. I did try storing the action sheet as data in the view controller so the reference was being kept, but to no avail.
I am using ARC.
EDIT: I tried an UIAlertView with the same results. Maybe it's the PDF context ruining things somehow?
Thanks for all the help everyone.
EDIT: Big breakthrough in solving this one: When commenting out my PDF generation code that's before my action sheet/modal dialog/alert view, it opens without complaint. So it's some kind of hybrid issue, and I'll post the majority of my method here so everybody can see what's up:
-(void)shareTapped:(id)sender
{
if (actionSheet.isVisible)
return;
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No mail setup" message:#"You must setup your email in the main settings app before you can share." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:#"ipc"];
[[PPCalculation sharedInstance] openCalculation:path];
}
[[PPCalculation sharedInstance] calculate];
// let's generate the PDF here!
NSMutableData* pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
UIGraphicsBeginPDFPage();
// 200 lines of drawing commands here
UIGraphicsEndPDFContext();
// save to file
NSString* path;
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString* filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:#"pdf"];
[[NSFileManager defaultManager] createFileAtPath:path
contents:pdfData
attributes:nil];
}
// ActionSheet, modal dialog, composer dialog, alert view, all of them crash when I try to put them here
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:#"Share" delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send By Email", nil];
[sheet showFromBarButtonItem:sender animated:YES];
}
Thanks again guys.
EDIT: It seems that, from my investigation and commenting things out line by line and sending them to the device over TestFlight that it's the internal data structures somehow not working properly, which is strange, as the rest of the app works fine. I probably will get a copy of Mountain Lion or something so I can debug this thing properly.
Try below code... May be it will help you...
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil];
//actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = ((UIButton*)sender).tag;
[actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
By sheer trial and error and commenting out code, I have narrowed it down to the PDF generation itself. Somewhere in the guts of the C++ data structures something is happening that is making iOS7 sad but the others fine. I've managed to convince the boss to order Mountain Lion so once that arrives I can build for iOS7 directly and debug it properly.
Try This it will help yo
your barbutton action method :
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil: delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil ];
[actionSheet showInView:self.view];
I'm building an app that allows the user to export en import data files and send them by e-mail.
So I've created a data file type with extension ".myAppExtension".
At first time everythings goes well. I can't export and send an e-mail. And when I open the e-mail, the method does work.
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (url != nil && [url isFileURL]) {
NSLog(#"%#",url);
NSLog(#"%#",[url pathExtension]);
if([[[url pathExtension] lowercaseString] isEqualToString:[#"myAppExtension" lowercaseString]]){
//Deal with received file
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Export ok" message:[NSString stringWithFormat:#"This file has been added : %#",[url lastPathComponent]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil,nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Export failed" message:[NSString stringWithFormat:#"This extention is not supported : %#",[url pathExtension]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil,nil];
[alert show];
}
}
return YES;
}
My issue is that when I want to export an other type of file with extension "otherExtension". I did not create data type for this extension in my app.
So I export and send an e-mail with this second type of file. The file name showed in e-mail "file.otherExtension". But, this is the issue, when I tap this mail attachement the e-mail app offers me to open it in my application. That's not what I want and, as I said, I did not create the data type for "otherExtension".
Edit : This is how I created the file type in myApp-info.plist :
If someone is interested, the issue were from the send e-mail fonction.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init] ;
[picker setSubject:mailSubject];
[picker addAttachmentData:codedData mimeType:#"application/myApp" fileName:[filePath lastPathComponent]];
[picker setToRecipients:[NSArray array]];
[picker setMessageBody:mailBody isHTML:NO];
[picker setMailComposeDelegate:self];
[currentMainViewController presentViewController:picker animated:YES completion:nil];
By adding the mime type to mail attachment the receiving application was using it to read the file. Replacing the mime type by "nil" solved my issue.
[picker addAttachmentData:codedData mimeType:nil fileName:[filePath lastPathComponent]];