objc2-message-ui 0.3.2

Bindings to the MessageUI framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-ui-kit")]
use objc2_ui_kit::*;

use crate::*;

/// Composition result sent to the delegate upon user completion.
///
/// This result will inform of the user's choice in regards to email composition.  If the user
/// cancels the composition,
/// <tt>
/// MFMailComposeResultCancelled
/// </tt>
/// will be sent to the delegate.
/// Typically
/// <tt>
/// MFMailComposeResultSent
/// </tt>
/// or
/// <tt>
/// MFMailComposeResultSaved
/// </tt>
/// will
/// be sent, but
/// <tt>
/// MFMailComposeResultFailed
/// </tt>
/// will be sent in the case of failure.
/// </p>
/// Send may only be interpreted as a successful queueing of the message for later sending.
/// The actual send will occur when the device is able to send.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/messageui/mfmailcomposeresult?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MFMailComposeResult(pub NSInteger);
impl MFMailComposeResult {
    #[doc(alias = "MFMailComposeResultCancelled")]
    pub const Cancelled: Self = Self(0);
    #[doc(alias = "MFMailComposeResultSaved")]
    pub const Saved: Self = Self(1);
    #[doc(alias = "MFMailComposeResultSent")]
    pub const Sent: Self = Self(2);
    #[doc(alias = "MFMailComposeResultFailed")]
    pub const Failed: Self = Self(3);
}

unsafe impl Encode for MFMailComposeResult {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for MFMailComposeResult {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// Error domain for NSError values stemming from the MFMailCompose API.
    ///
    /// This error domain is used as the domain for all NSError instances stemmming from the
    /// MFMailCompose API.  Valid error code values are declared in the
    /// <tt>
    /// MFMailComposeErrorCode
    /// </tt>
    /// space.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/messageui/mfmailcomposeerrordomain?language=objc)
    pub static MFMailComposeErrorDomain: &'static NSErrorDomain;
}

/// Error codes for NSError values stemming from the MFMailCompose API.
///
/// These error codes are used as the codes for all NSError instances stemmming from the
/// MFMailCompose API.  These are the only valid values for NSError instances with the
/// <tt>
/// MFMailComposeErrorDomain
/// </tt>
/// domain.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/messageui/mfmailcomposeerrorcode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MFMailComposeErrorCode(pub NSInteger);
impl MFMailComposeErrorCode {
    #[doc(alias = "MFMailComposeErrorCodeSaveFailed")]
    pub const SaveFailed: Self = Self(0);
    #[doc(alias = "MFMailComposeErrorCodeSendFailed")]
    pub const SendFailed: Self = Self(1);
}

unsafe impl Encode for MFMailComposeErrorCode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for MFMailComposeErrorCode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// The MFMailComposeViewController class provides an interface for editing and sending email.
    ///
    /// The MFMailComposeViewController class manages all user interaction.  The client needs to set the recipient or
    /// recipients.  The client may also set the subject and the body of the message.  Attachments may be added, if
    /// so desired.  After setup, the client needs to only display the view.
    /// <p>
    /// The provided delegate will be informed
    /// of the user's composition completion and how they chose to complete the operation.
    /// </p>
    /// Prior to use, clients
    /// should verify the user has set up the device for sending email via
    /// <tt>
    /// +[MFMailComposeViewController canSendMail]
    /// </tt>
    /// .
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/messageui/mfmailcomposeviewcontroller?language=objc)
    #[unsafe(super(UINavigationController, UIViewController, UIResponder, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "objc2-ui-kit")]
    pub struct MFMailComposeViewController;
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl NSCoding for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl NSObjectProtocol for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl UIAppearanceContainer for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl UIContentContainer for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl UIFocusEnvironment for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl UIResponderStandardEditActions for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
extern_conformance!(
    unsafe impl UITraitEnvironment for MFMailComposeViewController {}
);

#[cfg(feature = "objc2-ui-kit")]
impl MFMailComposeViewController {
    extern_methods!(
        /// Returns
        /// <tt>
        /// YES
        /// </tt>
        /// if the user has set up the device for sending email.
        ///
        /// The client may continue to set the recipients and content if the return value was
        /// <tt>
        /// YES
        /// </tt>
        /// .  If
        /// <tt>
        /// NO
        /// </tt>
        /// was the result, the client has a couple options.  It may choose to simply notify the user of the inability to
        /// send mail, or it may issue a "mailto" URL via
        /// <tt>
        /// -[UIApplication openURL:]
        /// </tt>
        /// .
        #[unsafe(method(canSendMail))]
        #[unsafe(method_family = none)]
        pub unsafe fn canSendMail(mtm: MainThreadMarker) -> bool;

        /// This property is the delegate for the MFMailComposeViewControllerDelegate method callbacks.
        #[unsafe(method(mailComposeDelegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn mailComposeDelegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn MFMailComposeViewControllerDelegate>>>;

        /// Setter for [`mailComposeDelegate`][Self::mailComposeDelegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setMailComposeDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMailComposeDelegate(
            &self,
            mail_compose_delegate: Option<&ProtocolObject<dyn MFMailComposeViewControllerDelegate>>,
        );

        /// This method sets the Subject header for the email message.
        ///
        /// This method will set the Subject header for the email message.  This should be called prior to display.
        /// Newlines are removed from the parameter.
        /// <p>
        /// After the view has been presented to the user, this method will no longer change the value.
        /// </p>
        ///
        /// Parameter `subject`: A NSString specifying the message's Subject header.
        #[unsafe(method(setSubject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSubject(&self, subject: &NSString);

        /// This method sets the To header for the email message to the specified email addresses.
        ///
        /// This method will set the To header for the email message.  This should be called prior to display.
        /// <p>
        /// Recipient addresses should be specified as per RFC5322.
        /// </p>
        /// <p>
        /// After the view has been presented to the user, this method will no longer change the value.
        /// </p>
        ///
        /// Parameter `toRecipients`: A NSArray of NSString instances specifying the email addresses of recipients.
        #[unsafe(method(setToRecipients:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setToRecipients(&self, to_recipients: Option<&NSArray<NSString>>);

        /// This method sets the CC header for the email message to the specified email addresses.
        ///
        /// This method will set the CC header for the email message.  This should be called prior to display.
        /// <p>
        /// Recipient addresses should be specified as per RFC5322.
        /// </p>
        /// <p>
        /// After the view has been presented to the user, this method will no longer change the value.
        /// </p>
        ///
        /// Parameter `ccRecipients`: A NSArray of NSString instances specifying the email addresses of recipients.
        #[unsafe(method(setCcRecipients:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCcRecipients(&self, cc_recipients: Option<&NSArray<NSString>>);

        /// This method sets the BCC header for the email message to the specified email addresses.
        ///
        /// This method will set the BCC header for the email message.  This should be called prior to display.
        /// <p>
        /// Recipient addresses should be specified as per RFC5322.
        /// </p>
        /// <p>
        /// After the view has been presented to the user, this method will no longer change the value.
        /// </p>
        ///
        /// Parameter `bccRecipients`: A NSArray of NSString instances specifying the email addresses of recipients.
        #[unsafe(method(setBccRecipients:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBccRecipients(&self, bcc_recipients: Option<&NSArray<NSString>>);

        /// This method sets the body of the email message to the specified content.
        ///
        /// This method will set the body of the email message.  This should be called prior to display.
        /// The user's signature, if specified, will be added after the body content.
        ///
        /// Parameter `body`: A NSString containing the body contents of the email message.
        ///
        /// Parameter `isHTML`: A boolean value indicating if the body argument is to be interpreted as HTML content.
        #[unsafe(method(setMessageBody:isHTML:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMessageBody_isHTML(&self, body: &NSString, is_html: bool);

        /// This method adds the specified attachment to the email message.
        ///
        /// This method adds the specified attachment to the email message.  This should be called prior to display.
        /// Attachments will be appended to the end of the message.
        ///
        /// Parameter `attachment`: NSData containing the contents of the attachment.  Must not be
        /// <tt>
        /// nil
        /// </tt>
        /// .
        ///
        /// Parameter `mimeType`: NSString specifying the MIME type for the attachment, as specified by the IANA
        /// (http://www.iana.org/assignments/media-types/). Must not be
        /// <tt>
        /// nil
        /// </tt>
        /// .
        ///
        /// Parameter `filename`: NSString specifying the intended filename for the attachment.  This is displayed below
        /// the attachment's icon if the attachment is not decoded when displayed.  Must not be
        /// <tt>
        /// nil
        /// </tt>
        /// .
        #[unsafe(method(addAttachmentData:mimeType:fileName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addAttachmentData_mimeType_fileName(
            &self,
            attachment: &NSData,
            mime_type: &NSString,
            filename: &NSString,
        );

        /// This method sets the preferred sending account of the email message.
        ///
        /// This method will set the sending account of the message to the specified email address if the user has an account with such an address set up. If there is no account with such an address, the default account will be used instead.
        /// The sending email address should be specified as per RFC5322.
        /// After the view has been presented to the user, this method will no longer change the value.
        ///
        /// Parameter `emailAddress`: A NSString specifying the preferred email address used to send this message.
        #[unsafe(method(setPreferredSendingEmailAddress:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPreferredSendingEmailAddress(&self, email_address: &NSString);

        #[cfg(feature = "block2")]
        /// Parameter `itemProvider`: specifying the intended content for collaboration
        ///
        /// Returns
        /// <tt>
        /// YES
        /// </tt>
        /// if the item provider was added to the composition successfully.
        ///
        /// If the return value is YES, the itemProvider was added to the composition.  The itemProvider must be non-nil.
        #[unsafe(method(insertCollaborationItemProvider:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn insertCollaborationItemProvider_completionHandler(
            &self,
            item_provider: &NSItemProvider,
            completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
        );
    );
}

/// Methods declared on superclass `UINavigationController`.
#[cfg(feature = "objc2-ui-kit")]
impl MFMailComposeViewController {
    extern_methods!(
        /// # Safety
        ///
        /// - `navigation_bar_class` probably has further requirements.
        /// - `toolbar_class` probably has further requirements.
        #[unsafe(method(initWithNavigationBarClass:toolbarClass:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithNavigationBarClass_toolbarClass(
            this: Allocated<Self>,
            navigation_bar_class: Option<&AnyClass>,
            toolbar_class: Option<&AnyClass>,
        ) -> Retained<Self>;

        #[unsafe(method(initWithRootViewController:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRootViewController(
            this: Allocated<Self>,
            root_view_controller: &UIViewController,
        ) -> Retained<Self>;

        #[unsafe(method(initWithNibName:bundle:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithNibName_bundle(
            this: Allocated<Self>,
            nib_name_or_nil: Option<&NSString>,
            nib_bundle_or_nil: Option<&NSBundle>,
        ) -> Retained<Self>;

        /// # Safety
        ///
        /// `a_decoder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            a_decoder: &NSCoder,
        ) -> Option<Retained<Self>>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "objc2-ui-kit")]
impl MFMailComposeViewController {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

extern_protocol!(
    /// Protocol for delegate callbacks to MFMailComposeViewController instances.
    ///
    /// This protocol must be implemented for delegates of MFMailComposeViewController instances.  It will
    /// be called at various times while the user is composing, sending, saving, or canceling email composition.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/messageui/mfmailcomposeviewcontrollerdelegate?language=objc)
    pub unsafe trait MFMailComposeViewControllerDelegate: NSObjectProtocol {
        #[cfg(feature = "objc2-ui-kit")]
        /// Delegate callback which is called upon user's completion of email composition.
        ///
        /// This delegate callback will be called when the user completes the email composition.  How the user chose
        /// to complete this task will be given as one of the parameters to the callback.  Upon this call, the client
        /// should remove the view associated with the controller, typically by dismissing modally.
        ///
        /// Parameter `controller`: The MFMailComposeViewController instance which is returning the result.
        ///
        /// Parameter `result`: MFMailComposeResult indicating how the user chose to complete the composition process.
        ///
        /// Parameter `error`: NSError indicating the failure reason if failure did occur.  This will be
        /// <tt>
        /// nil
        /// </tt>
        /// if
        /// result did not indicate failure.
        #[optional]
        #[unsafe(method(mailComposeController:didFinishWithResult:error:))]
        #[unsafe(method_family = none)]
        unsafe fn mailComposeController_didFinishWithResult_error(
            &self,
            controller: &MFMailComposeViewController,
            result: MFMailComposeResult,
            error: Option<&NSError>,
        );
    }
);