locked
iPhone Sample Questions. RRS feed

  • Question

  • Hi all, I am trying to use the iPhone sample that uses core data from preview v3 , and am trying to play with it to see how this all comes together. So I can then add to my existing App. I have the ListService( from v4 CTP) running on Win 7 IIS, and I can run the iPhone app and login, and Manage the list and items.

    Here are a few things that I noticed were not polished in the example and I need a little assistance on.

    1. To add an item you have to select a Priority & Status but when the iPhone app runs it does not populate these tabes in the core data. I opened the SQL light file directly and added these records based on what I saw in the tables in the MS Sql servers tables.
    2. Your comments in Sync Controller.m state that the syncBlog will be empty the first sync. This causes a problem in Util.M in GetODataJsonPayload, because when you try to populate your mainDict with
    .....dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithBool:false], serverBlob, nil] ....

    Because serverBlob is null or nil the first time, you get the error

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (1) not equal to number of keys (2)'

    This is because when you pass a nil object, like serverBlob in this case, Obj-c thinks thats the end of the array list, and doesn't add the nil object so one array has 2 objects and one has 1. So Sync wont start, thus the error above

    I added code to detect if serverBlog was nil and change it to a NSNull, this helped sync proceed past but it still will not complete.

    Here is the code I added right above  NSMutableDictionary *mainDict = [[NSMutableDictionary alloc] init];

    if(!serverBlob)
        {
            serverBlob = [NSNull null];
        }

    I now get the error from the server.

    iPhoneListSample[26919:207] Failed to upload changes Error Domain=org.brautaset.JSON.ErrorDomain Code=3 "Unrecognised leading character" UserInfo=0xb41f120 {NSLocalizedDescription=Unrecognised leading character} {
        NSLocalizedDescription = "Unrecognised leading character";
    }

    Can someone help, or provide a more polished example. I saw there is an example coming that uses SQL light connections, I see the value in Core data so I would like to see both examples in the future releases.

    Thanks
    Jeremy

     

    Thursday, November 4, 2010 5:03 PM

Answers

All replies

  • Hi Jeremy

    When you add a Priority and Status to the item, it just sets the Priority ID and the Status ID in the Item table, the Priority and Status table do not get modified.

    As for the serverBlob you should not change it to [NSNull null] for the first time you sync, when you login for the first time, the serverBlob is set to empty string, and that is what you send to the service in the json payload. If you have modified the sample and set the serverBlob to nil in the initial sync, you can modify your code to set it to @"" instead and this should work.

    Let me know if this helped.

     

     


    Maria del Mar Alvarez Rohena Microsoft Sync Framework
    Thursday, November 4, 2010 6:52 PM
  • I figured the Priority and status didn't sync but you cant add items if the tales are not populated.

    I actually tried @"" first but it didn't work, Same Error message.

     

    Failed to upload changes Error Domain=org.brautaset.JSON.ErrorDomain Code=3 "Unrecognised leading character" UserInfo=0x612e070 {NSLocalizedDescription=Unrecognised leading character} {
        NSLocalizedDescription = "Unrecognised leading character";
    }
    2010-11-04 14:03:15.669 iPhoneListSample[31199:207] Got response <ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorDescription>Missing Operation</ErrorDescription></ServiceError>

     

    please advise.


    Jeremy Wesley MCSE+I, MCP+I, MCSD, MCDBA Act!CC, ACT!PT, iPhone Dev
    Thursday, November 4, 2010 7:04 PM
  • Hi Jeremy

    It looks like you are trying to upload changes with an empty serverBlob.  This is not allowed by the protocol.  For initial sync you have to download changes first with empty blob, then upload changes (using the new blob received in the download changes response).

     


    Maria del Mar Alvarez Rohena Microsoft Sync Framework
    Thursday, November 4, 2010 7:42 PM
  • Where can i find the white paper on whats required by the protocal, Ive watched the videos and I look thru the 3.0 info and 4.0 stuff but I dont see it.

    I commented out the upload in the synchronize method in the SyncController and the app no longer crashes but  the log shows

    response string: <ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorDescription>Missing Operation</ErrorDescription></ServiceError>

    Missing Operation seems to be the common thread in all of these messages.

     

    The SyncBlob is still empty after the download only sync.

    Is the sample suppose to detect that its never synced with the server and skip upload? I dont see that logic in this sample.

    Jeremy

     


    Jeremy Wesley MCSE+I, MCP+I, MCSD, MCDBA Act!CC, ACT!PT, iPhone Dev
    Thursday, November 4, 2010 7:51 PM
  • There is a Protocol document in the SDK help file. That should be quite accurate with our implementation.


    Maheshwar Jayaraman - http://blogs.msdn.com/mahjayar
    Friday, November 5, 2010 5:22 PM
  • thx ill look there but any ideas what the Missing Operation error is all about?

    Jeremy

     


    Jeremy Wesley MCSE+I, MCP+I, MCSD, MCDBA Act!CC, ACT!PT, iPhone Dev
    Friday, November 5, 2010 5:25 PM
  • Ive looked at the the docs and here is what I found.

    in the iPhone sample the download and upload urls are

    self.uploadURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/DefaultScopeSyncService.svc/?syncScope=DefaultScope&operation=UploadChanges&userid=%@", self.baseURL, [anc valueForKey:@"userID"]]];
    self.downloadURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/DefaultScopeSyncService.svc/?syncScope=DefaultScope&operation=DownloadChanges&userid=%@", self.baseURL, [anc valueForKey:@"userID"]]];

    But According to the documentation in the OData + Sync:HTTP area under URI components says these paths should be formatted as such.

    self.downloadURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/DefaultScopeSyncService.svc/DefaultScope/DownloadChanges/?userid=%@", self.baseURL, [anc valueForKey:@"userID"]]];

    self.uploadURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/DefaultScopeSyncService.svc/DefaultScope/UploadChanges/?userid=%@", self.baseURL, [anc valueForKey:@"userID"]]];       

    If this change is made then the server returns the error No scope or template found on server.

    Ive tried to add debugging code to the server side but there's not much to debug since it appears there is only 5 lines of code.

    Can someone confirm that the iPhone example is correct or is the documentation correct. if the iPhone code is correct the why does the server return the error Missing Operation.

    Thanks
    Jeremy


    Jeremy Wesley MCSE+I, MCP+I, MCSD, MCDBA Act!CC, ACT!PT, iPhone Dev
    Friday, November 5, 2010 7:54 PM
  • The iphone sample is not updated with the release (I am surprised its even in the MSI as its not supposed to be). Are you using the older CTP sample? If yes then please wait for another week and the updated iPhone sample should be out pretty soon.

     


    Maheshwar Jayaraman - http://blogs.msdn.com/mahjayar
    Friday, November 5, 2010 8:27 PM
  • Yes, I have the iPhone sample from the v3 private preview. I will focus my work for the next week on writing my sync service while I anxiously await the updated iphone sample. I guess it wasn't clear that the iPhone sample would not work with the new bits. I interpreted the info about the iPhone sample for v4 was more of a SQL lite example instead of a coredata example. Personally I would keep it as a CoreData example ( that uses SQL light)

    Thanks for the info.

    Jeremy


    Jeremy Wesley MCSE+I, MCP+I, MCSD, MCDBA Act!CC, ACT!PT, iPhone Dev
    Friday, November 5, 2010 8:45 PM
  • The updated iPhone sample is now available with the Microsoft Sync Framework 4.0 October 2010 CTP bits, go to this page http://www.microsoft.com/downloads/en/details.aspx?FamilyID=afd89099-d589-423c-9762-78096aa95ac2&displaylang=en and follow the download instructions from the Download Instructions.mht link provided.
    Maria del Mar Alvarez Rohena Microsoft Sync Framework
    Thursday, February 3, 2011 10:02 PM