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
cbais7890
V2EX  ›  iDev

如何限制应用同时只能运行一个实例?

  •  
  •   cbais7890 · Jan 26, 2017 · 5526 views
    This topic created in 3422 days ago, the information mentioned may be changed or developed.
    7 replies    2017-01-26 21:26:21 +08:00
    phrack
        1
    phrack  
       Jan 26, 2017
    最好说明一下系统,语言,应用场景什么的吧。

    可以用 file lock , mutex , port lock ,反正就是资源占据,检查。
    wohenyingyu02
        2
    wohenyingyu02  
       Jan 26, 2017 via iPhone
    取同一个 bundle id
    cbais7890
        3
    cbais7890  
    OP
       Jan 26, 2017
    谢谢楼上提供的关键字, 找到了解决方案, 这里贴一下

    // 取 bundleId
    let bundleID = Bundle.main.bundleIdentifier!
    // 如果该 Bundle 执行的实例大于 1
    if NSRunningApplication.runningApplications(withBundleIdentifier: bundleID).count > 1 {
    // 退出
    NSApp.terminate(nil)
    }
    laoyur
        4
    laoyur  
       Jan 26, 2017
    很好奇在 iOS 上什么场景下需要?
    越狱开发?防止打包党多开?打包党都是换 bundleid 的呀
    cyr1l
        5
    cyr1l  
       Jan 26, 2017 via iPhone
    @laoyur 可能是 Mac App
    laoyur
        6
    laoyur  
       Jan 26, 2017
    @cyr1l #5 额,有道理
    cbais7890
        7
    cbais7890  
    OP
       Jan 26, 2017
    @cyr1l
    @laoyur
    对, 是 MacOS 上的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1360 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 17:02 · PVG 01:02 · LAX 10:02 · JFK 13:02
    ♥ Do have faith in what you're doing.