Working with iBeacon Assets

In addition to metadata, an iBeacon can be associated with one or moreAssets. An Asset is essentially a URL pointing to a resource along with some basic metadata (like content-type, size etc). The resource can be one of the following

  • a text file
  • a URL
  • a binary file
  • a JSON/Javascript file

You can use Assets to deliver content and new interactions to the application. For example, your app could deliver a store specific coupon or a daily special for a restaurant and keep it updated without having to do a application update.

The Asset interface

@interface LPAsset : NSObject
  
- (NSString *)assetId;

- (NSString *)contentType;

- (NSNumber *)size;

- (NSString *)name;

- (NSString *)url;

- (NSDictionary *)asDictionary;

- (long) lastModified;

- (long) lastRead;

@end
//in your LPBeaconManagerListener delegate 

- (void)beaconManager:(id)beaconManager didBecomeActive:(NSArray *)beacons {
    LPBeaconManager *lpBeaconManager = [LPBeaconManager sharedInstance];
    for(LPSensor *sensor in beacons){
        [lpBeaconManager getSensorAssets:[sensor uuid]
             andMajor: [[sensor major] intValue]
             andMinor: [[sensor minor] intValue]
             didComplete:^(NSDictionary *results, BOOL success) {
              if(success){
                  [self updateAssetsForSensor:sensor withAssets:results];
              }
          }];
    }
  ...
}

- (void)updateAssetsForSensor:(LPSensor *)sensor withAssets:(NSDictionary *)assets {
//    NSLog(@"Asset Collections:%@", assets);
    for(NSString *collName in [assets allKeys]){
        NSArray *items = [assets objectForKey:collName];
        for(LPAsset *item in items){
            [_inbox addItem:collName andItem:item];
         }
    }
}