Titanium application crashes when mail composer is displayed after selecting the email property in contact details window

StackOverflow https://stackoverflow.com/questions/14068556

문제

I'm working on an Titanium application which displays the contacts in iPhone. When user selects the email property of the user, I'm displaying the email composer window.

But my application is crashing and console displays:

** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <ABPeoplePickerNavigationController: 0xb1b7940> to <MFMailComposeViewController: 0x1508c880> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** First throw call stack:
(0x33fb012 0x2e4de7e 0x33fae78 0x923f35 0xf55d05 0xd544f3 0x33ef1bd 0x33ef0d6 0xd481c5 0xd53342 0x1fb1402 0x1fb1dbd 0x1fb1c30 0x11af4e9 0x370b53f 0x371d014 0x370d7d5 0x33a1af5 0x33a0f44 0x33a0e1b 0x31137e3 0x3113668 0xc6a65c 0x33c8 0x27d5)

I'm using the following code:

var values = {cancel:function(){}};
values.fields = ['firstName','email'];

function showContacts()
{
        Titanium.Contacts.showContacts(values);
};

values.selectedProperty = function(e) {
                if(e.property == 'email')
                {
                    var emailDialog = Titanium.UI.createEmailDialog();
                    emailDialog.subject = "Hello from Titanium";
                    emailDialog.toRecipients = [e.value];
                    emailDialog.messageBody = 'Appcelerator Titanium Rocks!';
                    if(emailDialog.isSupported())
                    {
                        emailDialog.open();
                    }
                }
            }

I know this error is because of I'm trying to display the email composer when the contact window is being dismissed.

How to display the email composer after dismissing the contact window?

Please help me. Thanks in advance.

도움이 되었습니까?

해결책 2

Finally I find a solution.

I wrote a sleep function and called it in the callback function. It solved my problem and crash is not happening... Hurray !!!

function sleepMyThread(milliseconds)
{
    var startTime = new Date().getTime();

    while((new Date().getTime() - startTime) < milliseconds)
    {
    }
}

And added the sleep method as the first statement of callback function.

 values.selectedProperty = function(e){
       sleepMyThread(777);
      //other stuffs
}

다른 팁

wrap the code in a setTimeout... I use it often when working with animations.

values.selectedProperty = function(e){
    setTimeout(function() {
        // DO SOMETHING...
    }, 200);
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top