Skip To Content

Access your content

In this topic

After you successfully connect to a portal or subscription within a portal using valid credentials, the user property 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 metadata describing the item. Items can be of various types such as web maps, tile packages, feature collections, and so on. Some types, such as globe documents or map templates, may only be relevant to desktop systems.

Based on item ID

Each item has a unique identifier. If you know the identifier, 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, 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) and implement the relevant methods:

//MyViewController.h file
@interface MyViewController : NSViewController <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 data is not retrieved. The binary or textual data needs to be explicitly fetched using fetchData. This allows a developer to work with an item using a minimum amount of memory and delay fetching the data until when it is 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, use the method fetchContent on AGSPortalUser. This returns a list of your folders and 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 owns the items
[portalUser fetchContent];

Note:

Portals do not currently allow sub-folders within a folder.

The results of fetchContent and fetchContentInFolder: are provided to the delegate of AGSPortalUser. Set one of your classes as the delegate to get these results or be informed of errors that occurred.

portalUser.delegate = self;

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

//MyViewController.h file
@interface MyViewController : NSViewController <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 that 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
}