rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

BW::Mail not working in production #402

Closed markrickert closed 9 years ago

markrickert commented 10 years ago

I'm getting reports of the BubbleWrap Mail functionality not working in production, and as usual, it's working for me from the app version from the app store. :cry:

Not sure if there's anything I can add to this other than:

This might be tricky to track down, so I've removed the BW::Mail code from my app and will be relying on the old method. For reference in RubyMotion, it's something like this:

  def email_receipt
    body = "Some Body with HTML"
    subject = "Some Subject Line"

    if MFMailComposeViewController.canSendMail
      mail_composer = MFMailComposeViewController.alloc.init
      mail_composer.mailComposeDelegate = self
      mail_composer.setSubject(subject)
      mail_composer.setMessageBody(body, isHTML:true)
      if mail_composer
        self.presentModalViewController(mail_composer, animated:true)
      else
        App.alert('There was a problem displaying the mail composer.')
      end
    else
      App.alert("No Email Account", {message: "You have not configured this device for sending email."})
    end
  end

  def mailComposeController(controller, didFinishWithResult:result, error:error)
    self.dismissModalViewControllerAnimated(true)
  end

Hopefully this will work in the app update :/

matthewsinclair commented 10 years ago

Mark, FWIW, I just tested my app (which uses BW::Mail) and I was able to send and receive an email.

markrickert commented 10 years ago

Yeah, I can too. But I've already had two reports of this in the wild. Not sure if this is a "bug", more than it's a "warning". I'll report back when I get this "manual" mail code into production.

Here's what I was using in the app:

  def email_receipt
    BW::Mail.compose(
      delegate: self,
      html: true,
      subject: "My subject",
      message: "My body",
    ) do |result, error|
      # result.sent?      # => boolean
      # result.canceled?  # => boolean
      # result.saved?     # => boolean
      # result.failed?    # => boolean
      # error             # => NSError
    end
  end

Wondering if it has anything to do with me not checking any of the result conditions? Dunno.

matthewsinclair commented 10 years ago

Huh. Stupid me. I just went and had a look at my code, and I'm not using BW::Mail. And in fact, my code is almost identical to your workaround code that you posted above. I thought I was using BW::Mail and now I can't recall why I went down that path. Ignore me!

markrickert commented 10 years ago

No worries. Thanks for clarifying.

hnishide commented 10 years ago

I had the same trouble. It looks because implementation of the method BubbleWrap::Mail.create_mail_controller is expecting the return value of MFMailComposeViewController.alloc.init always responds to mailComposeDelegate=. However if any mail account is not set up appropriately, MFMailComposeViewController.alloc.init returns nil.

markrickert commented 10 years ago

Some more information here... I contacted apple and they say that it's a known bug. ALl my interactions with them are logged here:

http://openradar.appspot.com/radar?id=5287901860462592

bewatts commented 9 years ago

@markrickert - Any update on this?

markrickert commented 9 years ago

Yeah, well i got an update from apple a few days ago saying they couldn't reproduce it and that "woosh" sound isn't an indication that the email is actually SENT.

Hello Mark,

This is a follow-up regarding regarding Bug ID# 17930344.

We need more information to investigate this issue.

The whoosh sound does not indicate that the message was sent (anymore), it's just the sound that plays when the user is finished composing the message.

I am not able to reproduce this with the attached sample project, however. Can you give us some more details about your account setup? Does the message at least show up in the outbox?

Please provide your response or results by updating your bug report.

Please compress any bundled files (e.g. nested folders) prior to uploading.

IMPORTANT: This is an automated email. Please do not respond to this email. Bug reports requiring your attention will appear under ‘Attention’ section. Please review this bug report and provide the requested information via the Apple Bug Reporter.

http://bugreport.apple.com

Thank you for your assistance in helping us discover and isolate bugs within our products.

Best Regards,

Developer Bug Reporting Team Apple Worldwide Developer Relations

myob commented 9 years ago

I can confirm that our app crashes due to undefined method `mailComposeDelegate=' for nil:NilClass (NoMethodError).
The method is sent in BubbleWrap mail/mail.rb to the object returned from MFMailComposeViewController.alloc.init
(line 37 of that file) There are no email accounts configured on our test device which replicates the case reported above by hnishide on Aug 18 I'll try replacing our BW code chunk with the workaround kindly provided by markrickert

If this cannot be fixed, perhaps Mail should be removed from BW as a partial answer to the 'bloat' issue? Or deprecated so people are aware there's an issue?

markrickert commented 9 years ago

@myob that's actually a different problem that I've addressed in #436 . You have to check if the email is configured on the device and handle it gracefully if mail accounts don't exist.

markrickert commented 9 years ago

Apple has moved on. Note that mail might not send in iOS 7. They indicated to me that this bug in ios 7 will not be fixed. All the more reason to make your apps iOS 8 only! :cry: