我有一个工作代码,但现在发现需要导入&通过电子邮件“打开”选项保存两个不同的Sqlite文件,我尝试使用UIAlertView创建不同的保存文件路径,但它似乎只能用一种方式
- (void)handleOpenURL:(NSURL *)urlx {
NSData *dbimport = [[NSData alloc] initWithContentsOfURL:urlx];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:dbimport forKey:@"import"];
[defaults synchronize];
NSLog(@"import saved");
databaseName = @"svrStoreData2.sql";
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSError *writeError = nil;
NSString *filePathx = [documentsPath stringByAppendingPathComponent:databaseName]; [dbimport writeToFile:filePathx atomically:YES];
if (writeError)
{
NSLog(@"Error writing file: %@", writeError);
}
}
两个文件都有特定的文件名,所以我想知道我是否可以使用“if equal to string”&在我同步NSUserDefaults以提供两个文件路径保存选项
之后使用if语句感谢您提前提供任何帮助
这是我的UIALertView尝试
UIAlertView *alertdata = [[UIAlertView alloc]
initWithTitle:@"What type of data do you want to import?"
message:@"Choose data type"
delegate:self
cancelButtonTitle:@"Import RM Name Data"
otherButtonTitles:@"Import Store Visit Data", nil];
NSInteger *buttonIndex = NULL;
NSLog(@"Button Index =%ld",(long)buttonIndex);
if (buttonIndex == 0)
{
}
else if (buttonIndex == 1)
{
databaseExportName = @"export.sql";
NSArray *pathssqlite3 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathssqliteDir2 = [pathssqlite3 objectAtIndex:0];
filePathsqlite3 = [pathssqliteDir2 stringByAppendingPathComponent:databaseExportName];
NSData *dbimport = [[NSData alloc] initWithContentsOfURL:urlx];
NSMutableData *dbimport = [[NSMutableData alloc] initWithContentsOfURL:urlx];
NSError *writeError = nil;
[dbimport writeToFile:filePathsqlite3 atomically:YES];
if (writeError)
{
NSLog(@"Error writing file: %@", writeError);
} } [alertdata show];
仍然试图解决,希望这会起作用,但仍然无法破解它
`- (void)handleOpenURL:(NSURL *)urlx {
NSData *dbimport = [[NSData alloc] initWithContentsOfURL:urlx];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:dbimport forKey:@"import"];
[defaults synchronize];
NSLog(@"import saved");
if([[urlx absoluteString] isEqualToString:@"svrStoreData2.sql"])
{
NSLog(@"If statement called");
//
databaseName = @"svrStoreData2.sql";
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSError *writeError = nil;
NSString *filePathx = [documentsPath stringByAppendingPathComponent:databaseName];
[dbimport writeToFile:filePathx atomically:YES];
if (writeError)
{
NSLog(@"Error writing file: %@", writeError);
}
//
else {
databaseExportName = @"export.sql";
NSString *documentsPathy = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSError *writeError = nil;
NSString *filePathy = [documentsPathy stringByAppendingPathComponent:databaseExportName];
[dbimport writeToFile:filePathy atomically:YES];
if (writeError)
{
NSLog(@"Error writing file: %@", writeError);
}
NSLog(@"If statement Not called");
}
}
}
`
答案 0 :(得分:0)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex(NSInteger)buttonIndex {
if ([alertView tag] == 14)
{
if (buttonIndex == 1)
{
[self reviewSave];
}
}
if ([alertView tag] == 11) {
if (buttonIndex == 1)
{
NSDictionary *defaultsDictionary = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
for (NSString *key in [defaultsDictionary allKeys]) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];}
}
}
解决了问题,我有另一个UIAlert,所以通过添加标签排序