0

iPhone 5 で連絡先を保存するために Appcelerator チタン sdk を使用しています。私のアプリは iOS 5 と iOS 6 シミュレーターで正常に動作していますが、iPhone 5 (物理デバイス) で実行し、連絡先を電話帳に保存するとクラッシュします。iPhone 4 および 4s デバイスとシミュレーターで完全に正常に動作しているため、何が問題なのかわかりません。

    addBtn.addEventListener('click', function(){

    var isContactPresent = 'false';
    var people = Titanium.Contacts.getAllPeople();

    for (var i = 0; i < people.length; i++) {
        Ti.API.info("People object is: "+people[i]);


        var title = people[i].fullName;
        if (!title || title.length === 0) {
            title = "(no name)";
        }

        if (win_3.titleStr === title) {

            Ti.API.info('Address Book ' + title);
            Ti.API.info('Contacts to be added ' + win_3.titleStr);

            isContactPresent = 'true';

            var dialog = Ti.UI.createAlertDialog({
            message: 'Contact has already been added in Address Book',
            ok: 'Ok',
            title: 'Contacts Present'
            }).show();

            break;

        } 
    }

    if(isContactPresent == 'false') {
            SaveContacts();

            var dialog = Ti.UI.createAlertDialog({
            message: 'Contact has been added successfully',
            ok: 'Ok',
            title: 'Contacts Added'
            }).show();
    }

    //alert('Contact has been added successfully');
});

function SaveContacts() {

    Ti.API.info('Win Email ' + win_3.emailStr);
    Ti.API.info('Win Phone ' + win_3.phoneStr);


    var contact_type = "home";

    var contact = Titanium.Contacts.createPerson();

    contact.kind = Titanium.Contacts.CONTACTS_KIND_ORGANIZATION;
    contact_type = "work";
    contact.organization = win_3.titleStr;

    if (win_3.emailStr != ' ' || win_3.emailStr != '') {
        contact.email = {contact_type: [win_3.emailStr]};
    } else {

        win_3.emailStr = ' ';
        win_3.emailStr = 'Testing';
        contact.email = {contact_type: [win_3.emailStr]};
    }

    if (win_3.phoneStr != ' ' || win_3.phoneStr != '') {
        contact.phone = {contact_type: [win_3.phoneStr]};
    } else {

        win_3.phoneStr = ' ';
        win_3.phoneStr = '11231323';
        contact.phone = {contact_type: [win_3.phoneStr]};
    } 

    Titanium.Contacts.save();

}
4

1 に答える 1

0

iOS6 では、アドレス帳に連絡先を追加するためにいくつかの連絡先のアクセス許可が必要です。

http://docs.appcelerator.com/titanium/release-notes/?version=2.1.3.GA#ios_6

于 2012-10-15T13:07:47.190 に答える