Add a print option to ShareKit - iphone

I am planning on using ShareKit in my App. I would also like to have printing (AirPrint). I was thinking to have all options( Facebook & Twitter & Printer ) in the same actionsheet.
Is there any reason why I shouldn't do that?
I have been looking for some tips on how to achieve this but have come up blank. There are tips to remove things from the ActionSheet but not add them. Would a printer option no be considered 'sharing'?

The process of adding an action to ShareKit is covered in "How to Add a New Action to ShareKit" This description assumes you have already implemented a core Sharekit functionallity (for example, you have implemented the ShareKit example program).
You will copy New Action templates from the ShareKit Template Src folder (.m and .h files) into your project, rename the files with the appropriate name (like "SHKPrint.m/.h"). There are some obvious things to change, like the class name and the header import file. Add #import "SHKSharer.h" to the header file.
Add the class to the actions/services list in SHKSharers.plist, as the linked page describes. (There really is no distinction at this point between an action and a service that I can see, and they may as well be grouped together, as far as I can tell, without problem. One distinction, though, is that actions are presumed to not require authentication. requiresAuthentication is method in the template.)
After that, as the documentation says, get familiar with Understanding the share flow.
At least one of the canShare methods needs to be overridden, and they are already set up in the template for you to modify and uncomment. I imaging that for your purpose, you might want to consider canShareText as an appropriate method to share, so change that one to return YES. Then you will be able to print using a printFormatter assigned to either UISimpleTextPrintFormatter or UIMarkupTextPrintFormatter (but not without setting up a UIPrintInteractionController). (I don't think you mentioned what you want to print, so you'll have to improvise.)
Modify the sharerTitle method in your new new sharer class, to show an appropriate title.
At this point, you should be able to run your code and see an action sheet. Your print action won't show up on this one, but if you click the more... button, it should show up on the second sheet.
Click that action and nothing will happen yet except the sheet will hide. Now you need to add some code to do the printing. (You will see later, if you choose to share again, the new action has been added to the first action sheet, which is a most-recently-used list.)
I mentioned that it was assumed you have already implemented a core ShareKit functionality, such as the ShareKit example program. If you go to the method that invokes the sharekit action sheet (in your own code, such as responding to your pressing the share button), you will see a place to establish what kind of information you want to share -- e.g., URL, image, text, ... This is independent of where you want to send your shared information -- printer, facebook, twitter, ... (which I think puts the cart before the horse, and I have modified my own implementation to fix this.) But, ignoring that for the time being, you will want to set it up something like this:
- (void) shareButtonPressed {
SHKItem *item = [SHKItem text:yourSimpleTextOrMarkupText];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showInView:self.view];
}
This puts the wheels into motion to share whatever is in the item object. The item object includes a shareType, which in this case is SHKShareTypeText, which is an enumerated type.
I won't go into the machinery that translates this into the shared result. I don't know it in my sleep yet, and might mislead you (if I haven't already).
When you click on the item in the action sheet, the SHKActionSheet class does some magic, converting the string name of your new action class (SHKPrint in this case) into a class, and using that to invoke a class method to allocate and initialize an instance of the same class. (I am doing this as I type, so I skipped the step on how this is accomplished from the "more..." second sheet. I'll leave it to the reader to trace that and see how it works.)
The sharing is done through a call chain running through share, then show methods in the SHKSharer class. (There is some business about autosharing that I won't get into here, but I think you can ignore that for the time being.) This finally lands on the send method of your custom class (SHKPrint). Look at your template file, and it will give you some guidance on what to do.
For more information on printing, see this link, which seems to give a pretty good example of what you can do to print.
I'll stop here for a couple of reasons. I think I answered your question, how to add an action sheet. Also, I don't have AirPrint capability to test with here, so I can't really go much further on my own.
Let me know if you have any other questions.

Related

Function across multiple view controllers

I am trying to make a function so that I request a 'manager override' where it presents a screen for a manager to enter their password and press an approve button. How should I do this? Will it have to be in multiple functions? Is there a way that I can call one function and it present the information back? Would a completion work for what I need? I have no ideas where to start for this.
My set up is as follows:
A view controller asks for manager approval, then a screen slides up with text boxes and an approve button. I want the approve button to trigger authenticating and dismissing the screen
Assuming you don't want a Framework target (that sounds like overkill for what you want) simply mark the function as "public" and move it outside of any class. I just tried in a sample project and it works.
It looks important - remember to keep it in a file already in the project. (My sample project didn't work with menu option File|Add|New|File.)
Now, if you really want portability, check out how to create a Framework project.

How can I use mnemonics on JavaFX 8 Alerts

I would like to be able to add accelerator keys for the buttons that are provided as a part of the Alert Dialog Controls included with JavaFX.
I am unsure if this is possible using the standard alert types ERROR, INFORMATION, CONFIRMATION, WARNING?
I created my own login window - which doesn't use an Alert structure and it works as follows:
When the stage opens up.
Then when the user hits the "ALT" key:
I would like the ability to "Hot Key" the buttons on the Alerts in the system. However, I am unsure if I can use the standard alerts, or if I need to create my own, and if so, how should I do that.
I really would like to use the Dialogs natively, if at all possible.
Thanks.
As far as I understood your question, I think it isn't possible without some extra code.
Looking at the code of OpenJFX the labels of the buttons are localized and fixed.
You might just want to create some buttons on your own by using the apropiate constructor which takes some buttons where you can override the existing ones.
EDIT: after rethinking everything, I tried to recreate your problem. You can see that project on GitHub..
This is the special code:
public void showCustomizedAlertWindow() {
Alert a = new Alert(AlertType.CONFIRMATION, "some content text", ButtonType.OK, ButtonType.CANCEL, ButtonType.FINISH);
((Button) a.getDialogPane().lookupButton(ButtonType.FINISH)).setText("_finished");
a.show();
}
But be aware, you are removing localization-support of that buttons.

How would one implement a sliding 2 button menu like this from Lift?

http://imgur.com/3ZBCsDn
Can't post the image on the site but there it is.
I have been trying to find if this is a template or a separate nib file ala the page turn animation. Any help would be greatly appreciated.
That is called a UIActionSheet. It is created entirely in code, so it's limited to some pretty simple stuff (i.e. a few buttons, one of which is the cancel button, and one of which can be marked "destructive"). Just consult the documentation for the UIActionSheet class; it tells you all there is to know about it.
Also, here's the discussion in my book:
http://www.apeth.com/iOSBook/ch26.html#_action_sheet

Is there an existing iOS component to type in a UITextView? [duplicate]

In my app I want the user to type names into a UITextField (or equivalent) and then when they press return, it will put that word(s) in a blue bubble that's usually associated with tags. The cursor then moves to the end where they can add more "tags".
This can be seen when adding contacts in the To, CC & BCC fields in the Mail app, and also when selecting contacts in the Messages app.
How is this done? Is it something that's provided in the UIKit or available somewhere else?
Many thanks,
Michael
Venmo just open sourced their token field.
https://github.com/venmo/VENTokenField.git
edited:
The equivalent control in desktop Cocoa is an NSTokenField, but there doesn't seem to be an equivalent for Cocoa Touch.
Since iOS 13 there exists UISearchTextField.
https://developer.apple.com/documentation/uikit/uisearchtextfield
You can see that component in action in the Photos App.
That should fit for many use cases. By removing the leftView you can also get rid of the search icon.
But be aware: You can‘t mix text and tokens at various positions.
From the docs:
Tokens always occur contiguously before any text in the search field.
Adding this here for reference:
Feel free to check out TaggerKit (a library I made), it's more or less what OP was talking about. You can basically add tags functionality to your app by just adding a view and a couple of properties.
I dont think you can do it with any built in functionality in the SDK, never seen such a feature. What you could do however is implement it yourself, have some custom blue button with some text over it, and when the user hits return you can have some code that takes the text and returns you the button that you need, shouldnt be too bad to implement

Is there an iPhone equivalent to the NSTokenField control?

In my app I want the user to type names into a UITextField (or equivalent) and then when they press return, it will put that word(s) in a blue bubble that's usually associated with tags. The cursor then moves to the end where they can add more "tags".
This can be seen when adding contacts in the To, CC & BCC fields in the Mail app, and also when selecting contacts in the Messages app.
How is this done? Is it something that's provided in the UIKit or available somewhere else?
Many thanks,
Michael
Venmo just open sourced their token field.
https://github.com/venmo/VENTokenField.git
edited:
The equivalent control in desktop Cocoa is an NSTokenField, but there doesn't seem to be an equivalent for Cocoa Touch.
Since iOS 13 there exists UISearchTextField.
https://developer.apple.com/documentation/uikit/uisearchtextfield
You can see that component in action in the Photos App.
That should fit for many use cases. By removing the leftView you can also get rid of the search icon.
But be aware: You can‘t mix text and tokens at various positions.
From the docs:
Tokens always occur contiguously before any text in the search field.
Adding this here for reference:
Feel free to check out TaggerKit (a library I made), it's more or less what OP was talking about. You can basically add tags functionality to your app by just adding a view and a couple of properties.
I dont think you can do it with any built in functionality in the SDK, never seen such a feature. What you could do however is implement it yourself, have some custom blue button with some text over it, and when the user hits return you can have some code that takes the text and returns you the button that you need, shouldnt be too bad to implement