Hi Humza,
I include the feature layer definition files in my app's bundle. When my app launches I copy the files to the app's Documents directory and then read the definitions from there to initialize the feature layers. The reason putting the files in the app's Documents directory is that should any of the definition changes I could use iTunes file sharing to update the files without having to recompile the app...
Cheers,
Shimin
@implementation FCNSWGISAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//an example of the definition file name: lineFeatureLayerDefinition.json
[FCNSWUtils copyFileInBoundleToDocumentsFolder:lineFeatureLayerDefinitionJsonFile withExtension:lineFeatureLayerDefinitionJsonFileExtension];
[FCNSWUtils copyFileInBoundleToDocumentsFolder:pointFeatureLayerDefinitionJsonFile withExtension:pointFeatureLayerDefinitionJsonFileExtension];
[FCNSWUtils copyFileInBoundleToDocumentsFolder:polygonFeatureLayerDefinitionJsonFile withExtension:polygonFeatureLayerDefinitionJsonFileExtension];
return YES;
}
@implementation FCNSWUtils
+(NSString *) documentsPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
+(void) copyFileInBoundleToDocumentsFolder:(NSString *)fileName withExtension:(NSString *)extension
{
NSString *documentDirectory = [self documentsPath];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithString:fileName]];
filePath = [filePath stringByAppendingString:@"."];
filePath = [filePath stringByAppendingString:extension];
//check if file is already in Documents folder
//if not, copy it from the bundle.
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:filePath])
{
//get the path of the file in the bundle
NSString *pathToFileInBundle = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
//copy the file in the bundle to the Documents folder
NSError *error = nil;
bool success = [fileManager copyItemAtPath:pathToFileInBundle toPath:filePath error:&error];
if(success)
{
NSLog(@"File copied from bundle to Documents.");
}
else
{
NSLog(@"%@", [error localizedDescription]);
}
}
}