2013-08-20 2 views
1

Sitecore Mobile SDK를 사용하여 기본 IOS 응용 프로그램을 만들고 있습니다. 지금까지 필요한 항목을 읽을 수 있었지만 Droplink 필드의 링크 된 항목에서 fieldvalue를 읽지 못했습니다.Sitecore Mobile SDK : DropLink의 linkedItem에서 값을 읽는 방법

나는이 코드를 사용합니다

SCApiContext* context = [SCApiContext contextWithHost: @"http://<myhost>/-/item"]; 
SCItemsReaderRequest* request = [ SCItemsReaderRequest new ]; 
request.requestType = SCItemReaderRequestQuery; 
request.request = @"/sitecore/content/Home/descendant::*[@@templatename='Content item']"; 
request.flags = SCItemReaderRequestReadFieldsValues; 
request.fieldNames = [ NSSet setWithObjects: @"Content title", @"Content author", @"Content introduction", @"Content date", @"Content body" , nil ]; 

    [context itemsReaderWithRequest: request](^(id result, NSError* error) 
    { 
     NSArray* items = result; 

     for (SCItem* item in result) 
     { 
      // get the author 
      __block NSString *author = @"empty"; 
      SCField *dropLinkField = [item fieldWithName: @"Content author"]; 

      [dropLinkField fieldValueReader](^(id result, NSError *error) 
      { 
       if (!error) 
       { 
        SCItem *linkedItem = result; 

        // TODO: author is not yet filled 
        NSSet *fieldsSet = [NSSet setWithObjects:@"Firstname", nil]; 
        // this method seems to be skipped 
        [linkedItem fieldsReaderForFieldsNames:fieldsSet](^(id result2, NSError *error2) 
         { 
          if (!error2) 
          { 
           NSDictionary *fields = result2; 
           SCField *field_ = [fields objectForKey: @"Firstname"]; 
           author = field_.rawValue; 
          } 
         }); 
       } 
      }); 


     } 

    } 

원래 항목이 읽기를하고 나는 droplink 필드의 필드 값을 읽을 수 있습니다. 또한 링크 된 항목을 읽을 수있는 것 같습니다. 항목 경로를 로그에 쓸 수 있기 때문입니다. 그러나 연결된 항목에서 필드를 읽으려고하면 해당 필드가 실패하고 "fieldsReaderForFieldsNames"메서드가 건너 뛴 것으로 보입니다. 내가 분명히 잘못 여기에 뭔가를하고 있지만, 문제를 간과하는 것있어

...

편집 :

은 내가 Sitecore 7을 사용하여 언급하는 것을 잊었다, 그것은 차이가 있는지 확실하지 않습니다. SCApiContext 및 SCItemReaderRequest를 만드는 위의 행을 추가했습니다.

나는 익명 액세스를 사용하고 "사이트 설정"으로는 제가 여러 필드에 필드를 원격 읽기 권한을 설정하지 않았기 때문에 나는이 문제를 발견 생각

itemwebapi.mode="StandardSecurity" 
itemwebapi.access="ReadOnly" 
itemwebapi.allowanonymousaccess="true" 

사용합니다. 그러나 해당 권한을 설정해도 해당 필드 및 필드 원격 읽기 세트가없는 다른 필드는 API에서 반환됩니다.

+1

1. 익명의 컨텍스트를 사용하고 있습니까? "sitecore"또는 "익스트라 넷"사용자로 인증하고 있습니까? 2. SCApiContext와 SCItemsReaderRequest를 생성하는 코드를 첨부 해 주시겠습니까? 3. ItemWebAPI.config의 "사이트"설정이란 무엇입니까? 일반적으로 "C : \ inetpub \ wwwroot \ _Your_Site_ \ Website \ App_Config \ Include"에 있습니다. 4. 액세스하려는 항목에 대해 Read, FieldRead 및 RemoteFieldRead 권한을 부여했는지 확인하십시오. 이것을 확인하려면 Access Viewer를 사용하십시오. Sitecore iOS SDK는 모든 항목 웹 API HTTP 요청을 로그에 씁니다. 이것들을 첨부 해 주시겠습니까? –

답변

1

Sitecore iOS SDK 작업 (아래 목록에서)은 백그라운드 작업 대기열에서 비동기 적으로 실행됩니다.
* fieldValueReader
* fieldsReaderForFieldsNames

이 그 저자 데이터가 당신이 그것을 액세스하는 순간에 다운로드 보증하지 않습니다.

완료 콜백 블록에서 다운로드 한 항목 및 필드를 사용하여 iPhone에 해당 항목이 있는지 확인하십시오.

[linkedItem fieldsReaderForFieldsNames:fieldsSet](^(id result2, NSError *error2) 
{ 
    NSLog(@"Read author field"); 
    if (!error2) 
    { 
    NSLog(@"No error"); 
    NSDictionary *fields = result2; 
    SCField *field_ = [fields objectForKey: @"Firstname"]; 
    author = field_.rawValue; 

    // Now all required fields will 
    // definitely be downloaded by the time you create a blog item 


    NSLog(@"voornaam: %@", author); 

    ParTechBlogItem *blogItem; 
    blogItem = [[ParTechBlogItem alloc] initWithTitle:[item fieldValueWithName:@"Content title"] 
               date:[item fieldValueWithName:@"Content date"] 
               intro:[item fieldValueWithName:@"Content introduction"] 
               author:author 
               text:[item fieldValueWithName:@"Content body" ]]; 
     [weakSelf addBlogItem:blogItem]; 
}