您的位置:首页 > 移动开发

如何判断用户是否为第一次进入app或者是第一次进入指定页面

2016-08-31 11:03 836 查看
1. 可以将版本号,或者判断第一次进入某页面的参数写在model中

#import <Foundation/Foundation.h>

@interface UserFirstLaunchModel :
NSObject

@property (copy,
nonatomic) NSString *appVersion;

@property (copy,
nonatomic) NSString *appBuild;

@property (nonatomic) BOOL isFirstLaunch;//第一次进入app

@property (nonatomic)
BOOL isHomeControllerFirstLaunch;//第一次进入首页

@property (nonatomic)
BOOL isOrderStatusControllerFirstLaunch;//第一次进入订单状态页

...

@end

2. 在app delegate中根据版本号判断是否第一次安装,取出缓存中的UserFirstLaunch对应的字典信息,与当前app比对版本号信息,如果不一致说明为第一次安装,就将app的版本号信息和首次进入的信息都初始化为YES后缓存到本地

- (void)judgeIsFirstLaunch{

    NSString *appVersion = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"];

    NSString *appBuild = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleVersion"];

//取出缓存中的UserFirstLaunch对应的字典信息,这里我把缓存中的信息整理放到单例中管理,意思知道了就可以了

    UserFirstLaunchModel *firstLaunchModel = [RMUserInfo
shareInstance].firstLaunchModel;

    if ( ![firstLaunchModel.appVersion
isEqualToString:appVersion] || ![firstLaunchModel.appBuild
isEqualToString:appBuild]) {

        NSDictionary *firstLaunchDict =
@{@"appVersion" : appVersion,
@"appBuild":appBuild,
@"isFirstLaunch": @YES, 

@"isHomeControllerFirstLaunch":
@YES,
@"isOrderStatusControllerFirstLaunch":@YES
};

        NSUserDefaults *userDefaults = [NSUserDefaults
standardUserDefaults];

        [userDefaults setObject:firstLaunchDict
forKey:@"UserFirstLaunch"];

        [userDefaults synchronize];

    }

}

3. 比如,要求第一次安装进入首页,加一个新手指引。就可以在viewDidAppear中判断是否为第一次安装进入首页,再添加一个新手指引的方法,然后在新手指引结束后修改本地信息。

//这是使用XSportView集成的新手指引方法,但是显示效果可能没有很理想,但是思路很好,你也可以把imageview铺到视图上,点击切换图片,最后移除

- (void)showXSportView{

    UserFirstLaunchModel *firstLaunchModel = [RMUserInfo
shareInstance].firstLaunchModel;

    if (!firstLaunchModel.isHomeControllerFirstLaunch) {

        return;

    }

    

    TXHXSportLight *SportLight = [[TXHXSportLight
alloc]init];

    SportLight.messageArray =
@[

      @"这是《天下货》",

      @"点这里可以切换地址",

      @"点这里查看消息",

    ];

    SportLight.rectArray =
@[

      [NSValue
valueWithCGRect:CGRectMake(0,
0, 0,
0)],

      [NSValue
valueWithCGRect:CGRectMake(kScreenWidth /
2, 40,
50,
20)],

      [NSValue
valueWithCGRect:CGRectMake(kScreenWidth -
20,
40, 40,
40)]

    ];

    [self
presentViewController:SportLight
animated:false
completion:^{

        NSMutableDictionary *firstLaunchDict = [firstLaunchModel
mj_keyValues];//这边用的是MJExtention框架,总之意思对了就可以了

        [firstLaunchDict setObject:@NO
forKey:@"isHomeControllerFirstLaunch"];//修改本地首次进入首页的信息,在做缓存,下次就不会走这个方法了。

        NSUserDefaults *userDefaults = [NSUserDefaults
standardUserDefaults];

        [userDefaults setObject:firstLaunchDict
forKey:@"UserFirstLaunch"];

        [userDefaults synchronize];

    }];

}

- (void)viewDidAppear:(BOOL)animated{

    [super
viewDidAppear:animated];

   
//设置状态栏文本颜色为白色

    [[UIApplication
sharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent];

 

    [self
showXSportView];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: