V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
jianzong
V2EX  ›  iDev

大家如何区分 production code 和 development code?

  •  
  •   jianzong ·
    haojianzong · 2015-03-06 10:34:43 +08:00 · 2934 次点击
    这是一个创建于 3358 天前的主题,其中的信息可能已经有所发展或是发生改变。
    譬如,
    1、通常开发链接的服务器和生成的服务器网站不一样;
    2、支付宝的沙箱环境和生产环境的配置;

    想实现在一行代码开关,全局切换的功能,应该怎样实现呢?
    10 条回复    2015-03-06 17:54:33 +08:00
    WildCat
        1
    WildCat  
       2015-03-06 10:35:41 +08:00
    Debug/Release?
    Livid
        2
    Livid  
    MOD
       2015-03-06 10:36:25 +08:00   ❤️ 2
    foccy
        3
    foccy  
       2015-03-06 10:50:35 +08:00
    根据环境加载配置文件。
    Elethom
        4
    Elethom  
       2015-03-06 11:06:01 +08:00 via iPhone
    用 macro,可以配合多 target。
    zhanglp888
        5
    zhanglp888  
       2015-03-06 11:13:21 +08:00
    我跟 @foccy 一样,根据环境,加载不同配置文件
    b821025551b
        6
    b821025551b  
       2015-03-06 11:21:00 +08:00
    if(current_ip='127.0.0.1'){
    include 'dev.ini';
    }else{
    include 'pro.ini';
    }
    b821025551b
        7
    b821025551b  
       2015-03-06 11:24:12 +08:00
    if(current_ip='127.0.0.1'){
    include 'dev.ini';
    }else if(current_ip='xxx.xxx.xxx.xxx'){
    include 'pro.ini';
    }else{
    echo 'Wrong Server IP'
    }

    6楼太不负责了。。。。
    jianzong
        8
    jianzong  
    OP
       2015-03-06 12:10:27 +08:00
    @Livid 很棒的资料,周末认真读一下。谢谢。
    jianzong
        9
    jianzong  
    OP
       2015-03-06 12:12:42 +08:00
    @b821025551b

    根据ip来判断不错。

    @zhanglp888
    @foccy
    想了一下,确实配置文件可以解决大部分问题了。谢谢各位。
    NCE
        10
    NCE  
       2015-03-06 17:54:33 +08:00
    @WildCat 这个不太保险,在线上出问题需要紧急调试的时候。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1024 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:31 · PVG 04:31 · LAX 13:31 · JFK 16:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.