Accessing your content

After you successfully connect to a portal or a subscription within a portal using valid credentials, the property user on AGSPortal contains a valid AGSPortalUser object representing a registered user.

Your items

An item is a unit of content in the portal. It is represented by an object of type AGSPortalItem. An item contains binary or textual data, and some metadata describing itself. Items can be of various types such as Web Maps, Tile Packages, Feature Collections, and so on. Some types, such as Globe Documents, Map Templates, etc, may only be relevant to desktop systems. Although you can access such items using the API, you may not be able to use them on a mobile device.

Based on Item Id

Each item has a unique identifier. If you know this identifier, you can instantiate an AGSPortalItem object using it as follows -

AGSPortal *portal = ... ; //The portal where the item resides
AGSPortalItem *portalItem = [[AGSPortalItem alloc] initWithPortal:portal itemId:@"<item_id>"];
When you instantiate the AGSPortalItem object, the item's metadata is fetched from the portal in the background. To verify the metadata was fetched properly, you must set one of your classes as the item's delegate
portalItem.delegate = self;

Your class must also adopt the <AGSPortalItemDelegate> protocol in the header file (.h file) and implement the relevant methods in the implementation file (.m file)

//MyViewController.h file
@interface MyViewController : UIViewController <AGSPortalItemDelegate>     
   ... 
@end


//MyViewController.m file
@implementation MyViewController
  ...
  
   - (void)portalItemDidLoad:(AGSPortalItem *)portalItem {
       //now it is safe to access the item's properties
   }
   
   - (void)portalItem:(AGSPortalItem *)portalItem didFailToLoadWithError:(NSError *)error {
      //handle or report the error
   }

@end

NoteNote:

Even when the item's metadata is loaded, the item's actual data is not retrieved. The actual binary or textual data needs to be explicitly fetched using fetchData. This allows a developer to work with an item using minimum amount of memory and delay fetching the actual data till when it is really needed.

Based on ownership

If you dont know the item's unique identifier, or if you want to access all items that belong to you, you can use the method fetchContent on AGSPortalUser. This will return to you a list of your folders and also any items you own that reside outside these folders. You can then use fetchContentInFolder: to retrieve items within a specific folder.

AGSPortalUser *portalUser = ... ; //The user who own the items
[portalUser fetchContent];

NoteNote:

Portals do not currently allow sub-folders within a folder

The results of fetchContent and fetchContentInFolder: are provided to the delegate of AGSPortalUser. You must set one of your classes as the delegate to get these results or be informed of any errors that were encountered.

portalUser.delegate = self;

Your class must also adopt the <AGSPortalUserDelegate> protocol in the header file (.h file) and implement the relevant methods in the implementation file (.m file)

//MyViewController.h file
@interface MyViewController : UIViewController <AGSPortalUserDelegate>     
   ... 
@end


//MyViewController.m file
@implementation MyViewController
   ...

   - (void) portalUser:(AGSPortalUser*)portalUser
             operation:(NSOperation*)op
       didFetchContent:(NSArray*)items
               folders:(NSArray*)folders
              inFolder:(NSString*)folderId	{  

      //process the items
      for (AGSPortalItem* item in items){
        ...
      }
   

      //also, iterate through the folders and fetch items within them
      for (NSString* folder in folders){
        [portalUser fetchContentInFolder:folder];
      }
   }

   - (void) portalUser:(AGSPortalUser*)portalUser
             operation:(NSOperation*)op
 didFailToFetchContentInFolder:(NSString*)folderId
             withError:(NSError*)error { 

      //handle or report error
   }

			

@end

Your groups

You can get information about the groups you belong to from the groups property on AGSPortalUser. This property contains an array of AGSPortalGroup objects which contain information about each group. Each group has a unique group identifier. You can use this identifier to search the portal for items belonging to that group.

NSArray* groups = portalUser.groups;
for(AGSPortalGroup* group in groups){
  //display group to the user
  //or fetch items within each group
}

See Also

5/9/2012