ios - Swift logout process -
i building app in swift interacts api. there 2 ways user can logged out, clicking logout button or receiving 401 response when calling api.
i plan on using nsnotificationcenter in api class broadcast event when unsuccessfully response received generic handling of things 401, 400, 500 can handled in 1 place outside of api class.
to prevent duplicating logic involved logging out in multiple places have created class clear existing tokens , present login view controller. class can used when logout button clicked in view controller or when 401 response picked response observer.
my problem is, since logic not inside view controller unsure how can present login view controller not have access method self.presentviewcontroller
you're going need pass responsibility view controller.
how i've handled in past using key-value observer (or rac) monitor active token. when token goes away, swap out root controller.
where depends on how you've structured things. app delegate reasonable spot.
Comments
Post a Comment