我正在使用 Appcelerator Titan 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();
}