Home > Software design >  Locking iOS Tabs from user
Locking iOS Tabs from user

Time:09-03

I want to block off different tabs from the users. As some tabs are as part of an in app purchase. How can I only let the user access the tab if the in app purchase is paid for.

I am using a key "user paid" to unlock features in the app, however i dont know how to lock the Tabs in the UI Tab bar. any ideas?

easiest thing i can think of is to add a view on each tab i want to block off and so when the user clicks on that tab the screen is blocked. i can then set these views to hidden once the user has paid. and at the loading of each view just check to make sure the user has paid before showing the details of the page to the user

CodePudding user response:

If you are instancing the UITabBarViewController by code, then you can disable some items of the TabBar with the following code:

if  let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray, tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
    tabBarItem.enabled = false
}

This specific code disables the third item of the TabBar (arrayOfTabBarItems[2]).

You can check whether or not the user should be accessing that specific tabBar item (for example check if the user is a premium user or not) and then enable the item accordingly.

Source: Disable TabBar Item Swift

  • Related