//
//  SignalBroadcasting.swift
//  Beacon
//
//  Created by Zhu Shengqi on 14/06/2017.
//  Copyright © 2017 zetasq. All rights reserved.
//

import Foundation

public protocol BroadcastIdentifiable: RawRepresentable {
  
  var rawValue: String { get }
  
}

public protocol SignalBroadcasting: class {
  
  associatedtype BroadcastIdentifier: BroadcastIdentifiable
  
  associatedtype BroadcastPayload
  
}

extension SignalBroadcasting {
  
  public func broadcast(identifier: BroadcastIdentifier, payload: BroadcastPayload, within beacon: Beacon = .default) {
    beacon.enqueueBroadcastRequest(broadcaster: self, identifier: identifier, payload: payload)
  }
  
  public static func uniqueBroadcastID(for broadcastIdentifier: BroadcastIdentifier) -> String {
    let bundleIdentifier = Bundle(for: self).bundleIdentifier!
    let className = "\(self)"
    
    return bundleIdentifier + "::" + className + "." + broadcastIdentifier.rawValue
  }
  
}


//
//  SignalBroadcasting.swift
//  Beacon
//
//  Created by Zhu Shengqi on 14/06/2017.
//  Copyright © 2017 zetasq. All rights reserved.
//

import Foundation

public protocol BroadcastIdentifiable: RawRepresentable {
  
  var rawValue: String { get }
  
}

public protocol SignalBroadcasting: class {
  
  associatedtype BroadcastIdentifier: BroadcastIdentifiable
  
  associatedtype BroadcastPayload
  
}

extension SignalBroadcasting {
  
  public func broadcast(identifier: BroadcastIdentifier, payload: BroadcastPayload, within beacon: Beacon = .default) {
    beacon.enqueueBroadcastRequest(broadcaster: self, identifier: identifier, payload: payload)
  }
  
  public static func uniqueBroadcastID(for broadcastIdentifier: BroadcastIdentifier) -> String {
    let bundleName = Bundle(for: self).object(forInfoDictionaryKey: kCFBundleNameKey as String) as! String
    let className = "\(self)"
    
    return bundleName + "::" + className + "." + broadcastIdentifier.rawValue
  }
  
}


--- 
+++ 
@@ -29,10 +29,10 @@
   }
   
   public static func uniqueBroadcastID(for broadcastIdentifier: BroadcastIdentifier) -> String {
-    let bundleName = Bundle(for: self).object(forInfoDictionaryKey: kCFBundleNameKey as String) as! String
+    let bundleIdentifier = Bundle(for: self).bundleIdentifier!
     let className = "\(self)"
     
-    return bundleName + "::" + className + "." + broadcastIdentifier.rawValue
+    return bundleIdentifier + "::" + className + "." + broadcastIdentifier.rawValue
   }
   
 }
Use bundleIdentifier to generate unique broadcast ID
