Objective C - How does Calendar adds file attachments to events? - objective-c

In OS X (tested in 10.8 and higher), it is possible to add a file attachment (like an email or a PDF file) in an already created or in-creation event by drag-and-dropping it into the event (EDIT: or event by selecting Add attachment/file).
A similar question was asked in 2013. According to the Mac Developer Libary, there is no place to store a file in EKCalendarItem or EKEvent. Still, Apple does it.
Does the Calendar app use the notes property in some way to store such file? Or does it upload the file to iCloud and link the file in the event to it?

There is no single answer to your question. It depends on the server (Fruux, iCloud, Exchange, Yahoo, ...), client version etc.
There is a simple answer to this: Can I attach files using the EventKit API? No, you can't. EventKit functionality is very limited. The 'notes' property maps to the (first or last? ...) iCalendar description property.
For iCloud and OSX server the OSX/iOS client should do CalDAV managed attachments. For servers not supporting this, the client might inline the attachments in iCalendar attachments. But if I remember right there are also cases in which the client keeps the attachment just local and refers to it via a file: URL in the ATTACH property.
Summary: If you want to attach files to iCloud (or other CalDAV servers), you need to implement a CalDAV client.

Related

Set client_mtime metadata via dropbox API

I'd like to be able to set the client_mtime in the dropbox file metadata. In the dropbox api docs it states
client_mtime For files, this is the modification time set by the
desktop client when the file was added to Dropbox, in the standard
date format. Since this time is not verified (the Dropbox server
stores whatever the desktop client sends up), this should only be used
for display purposes (such as sorting) and not, for example, to
determine if a file has changed or no
I'd like to be able to set this via the API. It clearly is possible to set because the desktop client does it but I can't find a documented way.
Is there a way to set this?
Replying to my own question a couple of years later...
The Dropbox v2 API does allow you to set client_modified when you upload a file now.
You don't appear to be able to change it without uploading the file again though.
[This answer is out of date. The Dropbox API v2 supports setting the modified time.]
This can't be explicitly set via the API, though it does get updated to the current time when you upload a file via the API.

Tracking file changes done by an external apps

Is it possible to get a handle on a file which is opened by any external app via my application?
Using Cloud-Storage Apps as an example, I would like to track changes to a file opened via the Storage-Provider App, so the manipulated file can be uploaded again afterwards.
There are two possible answers here, depending on what kind of app you're implementing.
For general tracking purposes, you can try using the ContentsChanged event of the StoreFolderQueryResult/StorageFileQueryResult classes within Windows.Storage.Search. That is, you create a file or folder query for what you want to watch, and then register an event handler. Generally speaking, this works well for stuff on the local file system; it's not guaranteed if you're trying to run a query on files/folders whose backing store is elsewhere.
The subject is too detailed to be described here, but you can refer the "File and Folder Queries" in Chapter 11 of my free ebook Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, page 607. Even though I focus on JS as a language, the discussions of WinRT APIs like this are useful when working in any language...plus the ebook is free so there's nothing to lose.
The other mechanism would be useful if you're implementing an app that provides the interface to a cloud storage backend, like the OneDrive app that's part of Windows. In this case you'd want to use the CachedFileUpdater contract. See Appendix D, page 1288, of my aforementioned book.

Saving a file to a specific location on WP8 device

I am new to Windows Phone 8 development. Would like to know if there is a way to store a file received to a particular location on device. It could be using an API, through ActiveSync or MDM.
Thanks in advance.
Windows Phone 8 doesn't allow for free-for-all direct access to the user's hard-drive to read or write files. You'll have to use usecase specific APIs depending on the type of media you're trying to store. I've answered a similar question in the past regarding WP8's read-write access for known file types # Windows Phone 8: Media file access
A few highlights:
Your app can use IsoStore to read & write files only accessable to your app. See IsolatedStorageFile API or ApplicationData.Current.LocalFolder API for that.
You can store pictures using MediaLibrary.SavePicture or MediaLibrary.SavePictureToCameraRoll methods.
You can store songs using MediaLibraty.SaveSong method.
Other then those APIs I'm not familiar with any other file write APIs to the OS from the top of my head. You can probably use a remote server, but that's pretty much it.

Get droplet path without making app document based

I have a fairly straightforward question about using droplets for my mac application. My app is not a document based app.
Is there any way to get the path of the item that was dropped? How would I go about implementing this if that was the case? I have looked into this, and it doesn't look like I can do droplets at all without making my app document based, which I really don't want to do.
Thanks ahead of time!
You don't have to use NSDocument at all to make a droplet. Just include CFBundleDocumentTypes in your Info.plist (see Storing Document Types Information in the Application's Property List for details) and implement application:openFile: in your app delegate (there are variants of this method for multiple files etc.).

how to programmatically send email using objective C / cocoa

Hi I am new to MAC OS development and I want to send an email programmatically trough an application, but without using Mail app like in SBSendEmail from apple's site. I dont want to attach any attachments, just a plain text email. What is the best and easiest way to do this? is it possible to use the basic functionality from SBSendEmail and automate the last step of sending mail through MAil app? Is there no easy way just like in C# to create a mail object and just send it?
Thank you.
There's no way to do this in pure Cocoa, except to use one of the three or four email libraries available (Pantomime is one I know of off the top of my head). The main problem with all of these is that they're designed for implementing a full email client, not just sending email, so they're probably more heavyweight than you need.
For Growl's MailMe display, I wrote a command-line mail-sending tool in Python. The Xcode project bundles this into the MailMe display plug-in bundle, and MailMe runs the tool using NSTask, passing the SMTP info it finds in the user's Mail preferences. Growl is also open source, so you can read the source to the MailMe display.
Things that won't work:
The Message framework, which has no public API in 64-bit.
The mail(1) tool, which requires the user to have the local SMTP server running (simple-mailer uses another SMTP server, whose name you pass in on the command line).
Note that MailMe currently does not understand how to look up MobileMe passwords, so it isn't yet able to send using MobileMe accounts. If you amend the code to do this, we'd appreciate a patch!
Another patch opportunity is that MailMe currently only looks in Mail's preferences for mail-sending settings. It could look in other clients' preferences, but does not yet know how to do that. If anyone who uses Thunderbird would like this capability, again, we'd appreciate a patch.
I would suggest you make use of /usr/lib/sendmail if present. Open a pipe to /usr/lib/sendmail and send the mail on stdin. This should be available the OS.