添加到联系人在iPhone 5上崩溃

时间:2012-10-15 09:27:03

标签: iphone ios6 titanium-mobile appcelerator-mobile

我正在使用Appcelerator钛sdk来保存iPhone 5上的联系人,我的应用程序在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();

}

1 个答案:

答案 0 :(得分:0)

iOs 6需要一些联系人权限才能将联系人添加到地址簿中:

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