Hi, It all depends on your project requirements and what you want to achieve / learn with it.
method #2 is simply using the macOS installed ping command to perform the ping. (equivalent of running ping from the terminal yourself).
method #1 is implementing the said ping command from scratch using sockets and creating the ICMP packet data manually.
If you want to learn more about networking go with #1, if you just want something that works but don't care about how or why #2.