i am currently developing an application for iOS which needs to communicate with a hardware device using a Socket Connection. Therefore i am using a Singleton Object with NSStream. To this point all works as expected.
The problem is if the connection is terminated, or interrupted it is not possible to reopen it (this is stated in the Documentation). So my idea is to destroy the Singleton and recreate it. This should not interfere with the Singleton Pattern, because it states that there only exists one copy of such a class.
Has anyone an idea how to solve this problem? Any other solution not involving the recreation of the singleton would be highly appreciated.
Why not put some logic in your singleton class to test if the connection to the device is active. If it has died, close the connection, and open a new one. This is effectively the same thing you are trying to do by destroying a recreating the singleton, but doesn't abuse the singleton pattern quite as much. It should also be simpler, because only the singleton knows about the connection, and thus keeps coupling low.