我很困扰。如何在使用应用程序时仅显示一次协议页面。我不知道如何解释这一点。但我正在尝试解释这一点。
我正在创建一个应用程序,其中有协议页面,其中有两个按钮
(1)按钮名称为Accept
(2)按钮名称为拒绝
如果用户单击接受按钮应用程序进入下一页,但当用户单击拒绝按钮应用程序退出应用程序。
但转折就在这里
如果用户第一次运行此应用程序,他会看到协议页面,并且如果用户接受此协议,那么只有在他继续前进之后。但当用户多次使用该应用程序时,如果他已经接受该协议,则不得再次看到该协议页面。请帮助我如何解决这个问题,我很困惑。
提前致谢
您可以通过 Alter View 应用协议页面
and
如果用户接受协议,则您将同意的值(可能是布尔值)存储在 plist 文件(可能来自应用程序的文档目录)中,然后每次您都可以检查它
代码“不显示协议”如果接受一次
将一个 plist 文件添加到资源文件夹中
在 plist 中添加一个布尔变量 将值设置为 UNCHECKED(REJECTED STATE)
//将plist复制到文档目录
-(void)CopyPlistTODocument
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Settings.plist"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
//NOW Call Another method that read data form plist of document directory
-(void)desclaimer
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *path =[documentsDirectoryPath stringByAppendingPathComponent:@"setting.plist"];
NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile: path];
BOOL *temp=[plist valueForKey:@"Agreement"];
//if the value of the temp got YES That Agreed earlier so no need to agreed again
if ([temp isEqualToString:@"NO"])
{
//Show Alert View From Here And call Method Accept() on the button pressed event of the accept button
}
}
//Now From Button Pressed Event Of The Accept Here is the Accept method
-(void)Accept
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *path =[documentsDirectoryPath stringByAppendingPathComponent:@"Settings.plist"];
NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile: path];
[plist setValue:@"YES" forKey:@"Agreement"];
//now every time the value read from here has agreed state so alert view will not get called
[plist writeToFile:path atomically:YES];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)