I'm trying to add a 'copy to notes' button in my app which sends a text to the notes app of ios. Is there any possible way to integrate this?
I've done some research and didn't find anything and since I've never seen it in an other app I guess it's not possible, but I thought It was worth a question.
Good question. Situations like the one you describe are always handled with URL schemes using the UIApplication method openURL:. For example, to launch the phone app with a specific number you could do:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1-234-567-8910"];
Or to launch the Mail app:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto:nobody#example.com"];
Just to show a few examples. The Apple URL Scheme Reference document describes all of the various URL schemes to integrate with different system apps. Nowhere in this document does it mention a URL scheme for the built in Notes app. If it were possible to send text to the Notes app, I would expect the document to advertise the fact. While it's not conclusive proof that it's not possible, I still think it should be cited as strong evidence of such.
Note that there are likely several third party note-taking apps that have their own custom URL scheme that may support launching with text.
Related
I've seen some apps that allow you to share content with ios's mail, messages, print and copy.
I see there is a project called sharekit that does something similar but integrates social network sharing. Personally I don't need the social sharing, so sharekit it probably overkill.
I just need to popup an actionsheet that will allowe me to pass some text for example to the mail app or the messages app.
What you are looking for is the MessageUI.framework.
This framework contains:
MFMailComposeViewController
this class will allow your user to compose an e-mail.
MFMessageComposeViewController this class will allow your to compose a SMS message. MMS is not supported.
You will have to write the action sheet you self, but after the user made there choice you can create an instance of MFMailComposeViewController or MFMessageComposeViewController and present it to the user.
Be aware that you will need to implement the MFMailComposeViewControllerDelegate and/or MFMessageComposeViewControllerDelegate to dismiss the view.
Look my answer here:
https://stackoverflow.com/a/13975189/736384
I wrote about the new UIActivity control, It let you do all you are looking for.
If all you want to do is integrate with Mail or Messages, use the MFMailComposeViewController and MFMessageComposeViewController classes respectively.
If you want to add support for Copy, Print, and other such "activities', take a look at the documentation for UIActivity and UIActivityViewController.
I know iOS is very strict about accessing sms and user data. But I wish to implement simple feature, something like log.
In my app user sends sms to another number (robot). And gets it's state back in sms. I know I can't access them in any way. But maybe I can set up a button which would simply show sms from certain number if there are any. Just to open Messages for a certain number that's all.
Is that possible, and can be accepted by Apple?
You can only send an sms. You cant view any messages. Check the apple documentation here.
Apart from usage of MFMessageComposeViewController, only option you have is to open the message app as,
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:"]];
Or just to pop up the sms app with number as,
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:1234567890"]];
Here is a similar question.
Update:
If you want to do this inside your app, you can use MFMessageComposeViewController. Check this apple documentation for more details on this.
I need to work on an application able to send a mail with automatic content (subject/text) that the user shouldn't be allowed to edit. Is it possible to do ?
Thanks for your advices
The answer is "no". If you want to use the MFMailComposeViewController class, you have to pay attention to this paragraph in Apple's documentation:
Important The mail composition interface itself is not customizable
and must not be modified by your application. In addition, after
presenting the interface, your application is not allowed to make
further changes to the email content. The user may still edit the
content using the interface, but programmatic changes are ignored.
Thus, you must set the values of content fields before presenting the
interface.
The user can (and should be able to) change anything and everything s/he wishes before they send out an e-mail.
If you don't want to follow those rules Apple set, there are other mail frameworks you can use within your iOS app.
Via the settings panel of your iPhone, you can add a subscription to a remote .ics calendar format. I have a Dutch iPhone app that does this from within the app (see the screenshot below, "abonneren op de agenda" means "subscribe to the calendar"), but there must be others too.
I want to mimic this behavior for a project of mine, but I can't find the API to do this with. It looks like it's not a part of EventKit, but because there's no app switching going on when you hit 'subscribe' in the example app I suspect it's also not a url scheme.
Who knows?
Try something like this:
NSString *url = #"http://server/filename.ics";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
This shows an uialertview with the question to the user if he/she wants to subscribe.
;)
I understand to do this on the iPhone you need to trap link requests (as per my other iPhone question UIWebView Expose JavaScript) and you can easily do the reverse and access JavaScript from Obj-C code.
However, I would like to have JavaScript be able to call some Objective-C functions that would somehow be registered with WebKit. I assume that you can do this better than trapping links like on the iPhone as on Mac OS X we have access to the full WebKit.
I wish to basically do the reverse of Using JavaScript from Objective-C
Update: For example is it possible to expose the objective-c method in JavaScript like self.external.objcmethod();
Have a look at my answer to this question, which is very similar. I provide code that shows you exactly how to do what you want.
Essentially, you need to implement the WebScripting protocol as per the documentation.
You don't need to define your own URL scheme handler, that is only necessary for iPhone applications. On the Mac the WebView object is many orders of magnitude more powerful than UIWebView on the iPhone and allows full bridging from JavaScript to Objective-C and vice versa.
You can browse to "javascript:my_method()" and intercept the loading...
Look at UIWebViewDelegate delegate.
Documentation at http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/Reference/Reference.html
Look at the method shouldStartLoadWithRequest
((BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType)
Addtionally, you may want to look at https://dev.mobileread.com/trac/webkitbrowser/browser/trunk/WebKit-r30377/WebKit/qt/Api/qwebframe.cpp#L167
The way I've done this in the past is to implement my own URL scheme. In your HTML pages, you'd create links like myapp://dosomefunction?aParameter=aValue. Mac OS X will open your application (if it's not already running) and pass it the URL when you click these links. It's slightly more convenient than trapping requests, and it would work with any web view anywhere on the system.
See the accepted answer to this question for details on how to set up the handler. Unfortunately, this is a one-way operation. You won't be able to get any return values back from the application.