His statement of giving up on you may have nothing to do with you.
This may be his way of avoiding the situation if he does not like conflict, does not know how to communicate his own needs, and finds the easy route to just blame his behavior on you.
If you have been forgiving him all of the time, he had made a habit out of acting this way knowing that you would accept him back when he returns to you. Why would he want to change his behavior? It suits him so far.
He may be ambiguous as far as what he wants out f a relationship and what his expectations of you are. It has to do with his emotional maturity level and it his own commitment to a relationship (which, he may not have) If you're going back and forth with him for 2 years, if things do not change, you may have another 2+ years of the same.
What would need to happen is for him to be able to communicate with you instead of resort to avoidance by leaving and blaming you. As far as how you can assist him in that, just point out to him how destructive his behavior is to the relationship. Insist that he tells you clearly what his expectations are of you, of himself and where does he see the relationship going. Ask him open ended questions and stick to the facts (of what you described his behavior had been towards you) He has to take responsibility and like you said he could have communicated even via text with you. You do not read minds.
Getting him back in your life would be something he himself has to initiate. If you're the one doing all of the work, he would not give you his 100% unconditionally. But, first he has to take responsibility for his actions and has to want to change and make the effort to do so.
If the two of you have mutual goals for the relationship, then you focus on that and take if from there. Find out what does he want and is willing to do.