The same code will work successfully when build to an iOS9 Device / Sim, and removing the
property resolves the issue for iOS8.
1. Create a Classic Project.
2. Include following demo code to app.js:
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
Ti.Contacts.requestAuthorization(function(e) {
if (e.success == true) {
alert('success');
}
else {
alert('no');
}
});
var createContact = Ti.UI.createButton({
title: "Create New Contact",
});
createContact.addEventListener('click',function(e){
pong = Ti.Contacts.createPerson({
firstName: 'letter',
lastName: 'pong',
middleName: 'long',
nickname: 'fancyPants',
prefix: 'Mr',
suffix: 'Jr',
firstPhonetic: 'a',
middlePhonetic: 'b',
lastPhonetic: 'c',
organization: 'appcelerator',
department: 'SDK',
jobTitle: 'pingPongChampion',
note: 'when i was young, i ping pong to the top',
kind: Ti.Contacts.CONTACTS_KIND_PERSON,
address:{
work:[
{
CountryCode: 'gb', // determines how the address is displayed
Street: '200 Brook Drive\nGreen Park',
City: 'Reading',
Country: 'England',
PostalCode: 'RG2 6UB'
},
{
CountryCode: 'gb', // determines how the address is displayed
Street: '1 St Pauls Road\nClerkenwell',
City: 'City of London',
State: 'London',
Country: 'England',
PostalCode: 'EC1 1AA'
}
],
home:[
{
CountryCode: 'gb', // determines how the address is displayed
Street: '2 Boleyn Court',
City: 'London',
State: 'Greenwich',
Country: 'England',
PostalCode: 'SE10'
}
]
},
email:{
home : [
'myGmail',
'myHotmail'
],
work : [
'myWorkemail'
]
},
relatedNames:{
father: 'baba',
mother: 'mama',
child: 'gaga'
},
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:{
main: ['07900 000001', '07900 000002'],
iPhone: ['+44 (0)118 925 6128', '+44 (0)118 000 0000']
},
alternateBirthday: {
calendarIdentifier: 'chinese',
day: 25,
era: 78,
isLeapMonth: false,
month: 11,
year: 16
},
socialProfile:{
home:[{
service: 'facebook',
username: 'jdeep@facebook.com'
},
{
service: 'gamecenter',
username: 'jdeep@hotmail.com'
}],
work:[{
service: 'linkedin',
username: 'jdeep@linkedin.com'
}]
},
url:{
homepage: ['www.google.com'],
work: ['www.appcelerator.com', 'www.example.com']
},
date:{
anniversary: ['2006-06-25T12:00:00.000+0000','2007-06-25T12:00:00.000+0000'],
other: ['2009-03-25T12:00:00.000+0000']
}
});
});
win1.add(createContact);
win1.open();
4. Build to iOS8 device / sim
5. Receive above error.
6. Remove
property.
7. Build to IOS8 device / sim.
8. Create Contacts works successfully.
Create contacts should work successfully on iOS8, or return a warning to exclude the relatedName property when building for iOS8.
The sample code is wrong. As according to the docs, relatedNames expect a dictionary of keys with values that are ARRAYs. HOWEVER, this also uncovered that the iOS9 implementation is wrong, fix coming shortly.
Master PR: https://github.com/appcelerator/titanium_mobile/pull/7467 5_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/7468 (Do not merge until 5.1.0.GA released)
To test:
Use the above sample code, but relatedNames should beAlright. The functionality works now, but only when modifying the provided demo code with the values of the last comment. I cleaned up the test case and provided some more details to check (null check after contact creation, 5.1.0 method for requesting permissions). Updated demo code (as stated in the docs): https://gist.github.com/hansemannn/01f37c1fc6f31e818abd
Verified as fixed, built the sample code using SDK
5.1.1.v20151123140433
to iOS9 device after modifying the relatedNames to the correct implementation. The contact was created successfully and the relatedNames fields have been saved correctly. Tested with: Devices: iPhones 6S+ (9.1) Simulators: (9.1) & (8.4) Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.1.v20151123140433 Appc Studio: 4.4.0.201511182122 Appc NPM: 4.2.2 Appc CLI: 5.1.0-60 Alloy: 1.7.26 Xcode 7.1(7B91b) Node v0.12.7 *Closing ticket.*To Note: This ticket is marked 5.1.2 but PR was merged in 5.1.1GA