0

我正在使用 PhoneGap 在 iPhone/Android 上保存联系人。总体而言,它似乎确实有效,但我已经追踪到最近的一次崩溃,即当我尝试将物理地址设置到我的contact() 对象中的contactAddress() 对象时,它会引发未捕获的异常。

我对要保存的联系人执行了 JSON.stringify:

{
    "id": 41,
    "rawId": null,
    "displayName": "Joe Customer",
    "name": {
        "givenName": "Joe",
        "familyName": "Customer"
    },
    "nickname": null,
    "phoneNumbers": [
        {
            "name": "work",
            "value": "2145556666",
            "pref": true
        },
        {
            "name": "fax",
            "value": "2147778888",
            "pref": true
        }
    ],
    "addresses": [
        {
            "streetAddress": null,
            "locality": "Dallas",
            "region": null,
            "postalCode": null,
            "country": null
        }
    ],
    "ims": null,
    "organizations": [
        {
            "pref": true,
            "type": "work",
            "name": "Acme Inc.",
            "department": null,
            "title": "Sales Person"
        }
    ],
    "birthday": null,
    "note": null,
    "photos": null,
    "categories": null,
    "urls": [
        {
            "name": "website",
            "value": "http://www.google.com",
            "pref": true
        }
    ]
}

当我尝试保存它时,我得到了异常:

2012-09-06 21:50:38.358 MyApp[6224:707] typeValue: (null)

2012-09-06 21:50:38.359 MyApp[6224:707] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> -[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: type)

无论我是填写整个地址对象还是只填写一个字段,它似乎都会发生。

4

1 回答 1

1

I think you have to set the 'rawId' field of the contact. I did also have a problem saving contacts on Android devices when working with Phonegap 2.1 and Sencha Touch 2.0 and I got a similar log output, something with "invalid argument: int is 'null'" or something. The problem was solved when I realized that I had to set the rawId of the contact.

In my case, I just wanted to update an already existing contact so I set the id of my contact object, contactToSave, to the same id as the contact I wanted to update. But when contactToSave.save() executed, there was the beforementioned error.

When I set not only the id but also the rawId of contactToSave to the same as the contact in the phonebook, the problem disappeared and I could update contacts without problem.

Try setting the rawId of your contact, though I don't know to what value, since it is a new contact.

于 2012-12-07T09:01:50.057 回答