Add casts and #ifdef to address some compiler issues on iOS8 and Windows

This commit does not add new functions or other code changes.