Accessing content

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

Items

An item is a unit of content in the portal. It's 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 and map templates, 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.

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

Note:

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 you to work with an item using a minimum amount of memory and delay fetching the actual data until it's really needed.

Ownership

If you don't know the item's unique identifier, or if you want to access all items that belong to you, you can use the fetchContent method on AGSPortalUser. This returns a list of your folders as well as items you own that reside outside these folders. You can then usefetchContentInFolder: to retrieve items within a specific folder.

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

Note:

Portals do not currently allow subfolders 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

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 Searching 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


In this topic
  1. Items
  2. Groups
  3. See also