我正在使用复制和粘贴解决方案将联系人保存到 iOS 6 上的通讯簿中,但在文档中发布的解决方案在 Titanium(Appcelerator)中保存联系人不起作用,
if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
Ti.API.info('Saving contact...');
Ti.Contacts.createPerson({
firstName: 'Paul',
lastName: 'Dowsett',
address:{
work:[
{
CountryCode: 'gb', // determines how the address is displayed
Street: '200 Brook Drive\nGreen Park',
City: 'Reading',
County: 'Berkshire',
Country: 'England',
ZIP: 'RG2 6UB'
},
{
CountryCode: 'gb', // determines how the address is displayed
Street: '1 St Pauls Road\nClerkenwell',
City: 'City of London',
State: 'London',
Country: 'England',
ZIP: 'EC1 1AA'
}
],
home:[
{
CountryCode: 'gb', // determines how the address is displayed
Street: '2 Boleyn Court',
City: 'London',
State: 'Greenwich',
Country: 'England',
ZIP: 'SE10'
}
]
},
birthday: '2012-01-01T12:00:00.000+0000',
instantMessage:{
home:[
{
service: 'AIM',
username: 'leisureAIM'
},
{
service: 'MSN',
username: 'no_paul_here@msn.com'
}
],
work:[
{
service: 'AIM',
username: 'seriousAIM'
}
]
},
organization: 'Appcelerator',
phone:{
mobile: ['07900 000001', '07900 000002'],
work: ['+44 (0)118 925 6128', '+44 (0)118 000 0000']
},
url:{
homepage: ['www.google.com'],
work: ['www.appcelerator.com', 'www.example.com']
}
});
Ti.API.info('Contact saved');
Ti.API.info('Saving contact...');
var workAddress1 = {
'CountryCode': 'us',
'Street': '440 N. Bernardo Avenue',
'City': 'Mountain View',
'State': 'California',
'Country': 'United States',
'ZIP': '94043'
};
Ti.Contacts.createPerson({
firstName:'Arthur',
lastName:'Evans',
address:{
'work':[workAddress1]
}
});
Ti.API.info('Contact saved');
} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
alert('Unknown Not allowed');
Ti.Contacts.requestAuthorization(function(e){
if (e.success) {
performNewAddressBookAddition();
//performAddressBookFunction();
} else {
addressBookDisallowed();
}
});
} else {
addressBookDisallowed();
}
我也允许 iOS 6 和 iPhone 5 的所有权限,但解决方案适用于带有 iOS 6 的 iPhone 4 和 4s,但不适用于 iPhone 5 物理设备。
http://developer.appcelerator.com/question/144463/solution-for-contact-saving-is-not-working-on-iphone-5-device