【问题标题】:Create same app for multiple user为多个用户创建相同的应用程序
【发布时间】:2015-04-12 03:39:24
【问题描述】:

我为一个用户(/角色类型)开发了一个应用,现在希望为同一个应用添加更多角色。所以现在,不同的角色将显示/隐藏一些功能取决于分配的角色。显然,我将在单个应用程序中输入相同的登录页面,这是检查角色的起点。这样做将节省我的应用程序的屏幕计数。如何有效地做到这一点?

任何显示登录的多个角色的设计想法也将被接受。

【问题讨论】:

  • 我不明白这个问题。你遇到了什么问题?
  • 我没有问题,我只需要一个适当的方法来实现上述要求。主要根据角色显示/隐藏功能。我是通过使用标志来考虑的,但我猜这不是一个有效的解决方案....

标签: ios iphone storyboard xcode5


【解决方案1】:

我猜你可以创建一个位掩码枚举来代表你的不同角色

typedef enum : NSUInteger {
  RoleType1 = (1 << 0), // = 001
  RoleType2 = (1 << 1), // = 010
  RoleType3 = (1 << 2)  // = 100
} RoleType;

使用位掩码可以为用户分配多个角色

例如,您可以这样做:

RoleType myRoles = RoleType1|RoleType2 // here myRoles = 011

将 RoleType1 和 RoleType2 分配给您的用户

然后在某个地方存储这个(AppDelegate @property 也许?)

@property (nonatomic) RoleType myRoles;

((AppDelegate*)[[UIApplication sharedApplication] delegate]).myRoles = RoleType1|RoleType2

然后您只需要测试您的用户必须在屏幕中显示某些内容或在菜单中的条目等角色...

// We get the current roles
RoleType myRoles = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).myRoles
if (myRoles & RoleType1) { // This is the way to test if myRoles and RoleType1 have a common bit
  // Then user has role1, then we want to show a button for example
  button.hidden = NO;
} else {
  // User does not have role1
  button.hidden = YES
}

【讨论】:

  • 感谢您的宝贵回复。我希望你能详细介绍一下它的实现细节。
  • @user2741735 我添加了更多细节
猜你喜欢
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
  • 2019-04-20
  • 2020-08-12
  • 1970-01-01
  • 2020-01-12
相关资源
最近更新 更多