evermeer / EVCloudKitDao

Simplified access to Apple's CloudKit
Other
645 stars 65 forks source link

*** Terminating app due to uncaught exception 'CKException', reason: 'recordType (AppMessage.Message) contains invalid characters' *** #7

Closed allen8300 closed 9 years ago

allen8300 commented 9 years ago

Hi there, I kept crashing here: EVCloudKitDao.publicDB.createRecordTypes([Message(), Asset(), News()])

With error: *\ Terminating app due to uncaught exception 'CKException', reason: 'recordType (AppMessage.Message) contains invalid characters'


Here is the log: AppMessage.Message { hash = -751037153 key = MessageType, value = T key = From_ID, value = key = encodedSystemFields, value = key = Asset, value = key = creatorUserRecordID, value = key = FromLastName, value = key = Asset_ID, value = key = recordType, value = key = ToFirstName, value = key = Longitude, value = 4.8653827 key = FromFirstName, value = key = To, value = key = creationDate, value = 2015-05-20 05:16:35 +0000 key = To_ID, value = key = Text, value = key = lastModifiedUserRecordID, value = key = modificationDate, value = 2015-05-20 05:16:35 +0000 key = ToLastName, value = key = From, value = key = recordID, value = <CKRecordID: 0x7b088f10; 96F70DAC-8AA2-4F46-A027-D8368155B014:(_defaultZone:defaultOwner)> key = recordChangeTag, value = key = Latitude, value = 52.8350711 }

evermeer commented 9 years ago

It looks like that for some reason EVReflection did not clean up the classname. It should have cleaned AppMessage.Message into Message. For some reason it left your application name in there. Because of this it will try to create a recordType with the name AppMessage.Message. There is a dot in that name. It looks like this is an illegal character in CloudKit. On my machine it does clean it up correctly (see log snippet below). So let me see if I can still find out what's the cause of this.

05/20/2015 08:21:52:904 AppMessage)[37316:.] EVCloudKitDao.swift(281) createRecordTypes:
    saveItem Message {
   hash = -7749894181229782760
...
evermeer commented 9 years ago

I have a question, Did you change the bundle identifier of your app so that it does not match your app target name? So the bundle identifier does not contain something like $(PRODUCT_NAME)?

That's probably it. I think that prevented the removal of the AppMessage. part from the class name in your case. I tried changing it to just remove everything up to the dot, but then when I try to create a class from a string, it does not know the product name.

So a quick fix in your case is by making sure your bundle name is the same name as your target. I have to find out if there is a way to retrieve the target name from something else than the bundle.

allen8300 commented 9 years ago

Thanks so much for your kindly replying!
Yeah, you are right! I also found that issue. So I was trying to change all strings like AppMessage.Message into Message. The app can run successfully now. Now the new issue is, the app crashes when I try to send message to another contact. Following is the log, can you tell where maybe wrong?

ChatViewController.swift(112) initializeCommunication(): Conversation message inserted AppMessage.Message { hash = -7761184408764535057 key = lastModifiedUserRecordID, value = key = Latitude, value = 52.8350711 key = Longitude, value = 4.8653827 key = creationDate, value = 2015-05-20 08:06:34 +0000 key = creatorUserRecordID, value = key = recordChangeTag, value = key = FromLastName, value = Allen key = FromFirstName, value = Richard key = modificationDate, value = 2015-05-20 08:06:34 +0000 key = Text, value = Hello key = Asset_ID, value = key = To_ID, value = _04ddfafc17d977709022eea334fe4ca4 key = From, value = <CKReference: 0x170820cc0; _f9215c972175543145515e7912c999d0:(_defaultZone:defaultOwner)> key = MessageType, value = T key = ToLastName, value = Li key = Asset, value = key = recordID, value = <CKRecordID: 0x170820c40; A050ACCE-DBD4-4833-A04E-D0FC658BE0CC:(_defaultZone:defaultOwner)> key = ToFirstName, value = Jolie key = From_ID, value = _f9215c972175543145515e7912c999d0 key = recordType, value = key = encodedSystemFields, value = key = To, value = <CKReference: 0x170821140; _04ddfafc17d977709022eea334fe4ca4:(_defaultZone:defaultOwner)> }

05/20/2015 16:06:34:516 AppMessage)[17321:.] ChatViewController.swift(126) initializeCommunication(): Some conversation data was changed

fatal error: unexpectedly found nil while unwrapping an Optional value

allen8300 commented 9 years ago

Hi evermeer, everything is solved and working now. The reason is the bundle identifier must end up with the product name, otherwise things will happen like AppMessage.Message. Thanks all the same. You can close this now.

evermeer commented 9 years ago

Thanks!

I did changed the EVReflection class a little so that it will first look at the bundle name since the chance is bigger that the bundle name will be the same as your target name. Unfortunately there is no other way to get the name of the target. You will get that change if you run a 'pod update' But since you have renamed your bundle identifier you don't need that change.