I'm trying to get my Wink Hub working with Pubnub subscriptions in my iOS app, but all I ever get is a PNUnexpectedDisconnectCategory status in the didReceiveStatus callback.
Here is the code:
class AppDelegate: UIResponder, UIApplicationDelegate, PNObjectEventListener {
var window: UIWindow?
var client: PubNub
override init() {
let configuration = PNConfiguration(publishKey: "", subscribeKey: "fake-key")
client = PubNub.clientWithConfiguration(configuration)
super.init()
client.addListener(self)
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
client.subscribeToChannelGroups(
["sensor-channel0",
"sensor-channel1"],
withPresence: false)
return true
}
func client(client: PubNub, didReceiveMessage message: PNMessageResult) {
print("receivedMessage")
}
func client(client: PubNub, didReceiveStatus status: PNStatus) {
if status.category == .PNUnexpectedDisconnectCategory {
print("disconnected")
// This event happens when radio / connectivity is lost.
}
}
The subscribe and channel keys are taken straight from the device subscription data returned by the Wink API, so I am not sure what I am doing wrong. Any help would be appreciated!
Related
I'm using Firebase Remote Config, I have some troubles to update values.
My values are updated only if I close and relaunch the app.
But never if my app enters in foreground.
The developer is activated, with no cache delay.
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let _ = RCFirebaseValues.sharedInstance
}
}
My Firebase Remote Config class:
enum ValueKey: String {
case force_update
}
class RCFirebaseValues {
static let sharedInstance = RCFirebaseValues()
var loadingDoneCallback: (() -> ())?
var fetchComplete: Bool = false
private init() {
loadDefaultValues()
fetchCloudValues()
}
func loadDefaultValues() {
RemoteConfig.remoteConfig().setDefaults(fromPlist: "RemoteConfigDefaults")
}
func fetchCloudValues() {
#if DEBUG
let expirationDuration: TimeInterval = 0
RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings(developerModeEnabled: true)
#else
let expirationDuration: TimeInterval = 3600
#endif
RemoteConfig.remoteConfig().fetch(withExpirationDuration: expirationDuration) {
[weak self] (status, error) in
guard error == nil else {
DLog(message:"Uh-oh. Got an error fetching remote values \(String(describing: error))")
return
}
RemoteConfig.remoteConfig().activateFetched()
self?.fetchComplete = true
self?.loadingDoneCallback?()
}
}
func bool(forKey key: ValueKey) -> Bool {
return RemoteConfig.remoteConfig()[key.rawValue].boolValue
}
func string(forKey key: ValueKey) -> String {
return RemoteConfig.remoteConfig()[key.rawValue].stringValue ?? ""
}
func double(forKey key: ValueKey) -> Double {
if let numberValue = RemoteConfig.remoteConfig()[key.rawValue].numberValue {
return numberValue.doubleValue
} else {
return 0.0
}
}
}
What's wrong?
EDIT after Mosbah's response:
class AppDelegate: UIResponder, UIApplicationDelegate {
var remoteConfig:RCFirebaseValues!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
self. remoteConfig = RCFirebaseValues.sharedInstance
}
}
Your RCFirebaseValues scope is wrong, it will be nil as soon as you are out of application: didFinishLaunchingWithOptions: so you should keep a strong reference to your object (create a var on AppDelegate).
I've integrated Chartboost into my app and I am able to see ads, but I don't have a firm grasp of delegates and I am having trouble using the Chartboost provided code to cause actions to occur after an ad is viewed. My app delegate code is below (i replaced the actual appid and signature that I'm using):
class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
application.isStatusBarHidden = true
Chartboost.start(withAppId: "appID", appSignature: "appSignature", delegate: self)
Chartboost.cacheRewardedVideo(CBLocationHomeScreen)
Chartboost.cacheInterstitial(CBLocationHomeScreen)
func didDisplayInterstitial(_ location: String!){print("didDisplayI")}
func didCloseInterstitial(_ location: String!){print("didCloseI")}
func didDismissInterstitial(_ location: String!){print("didDismissI")}
return true
}
Then in my ViewController I have the following:
class CharacterCreationViewController: UIViewController, ChartboostDelegate {
weak var delegate: ChartboostDelegate?
Override func viewDidLoad() {
super.viewDidLoad()
Chartboost.setDelegate(self)
}
#IBAction func watchAd(_ sender: Any) {
Chartboost.showInterstitial(CBLocationLevelStart)
delegate?.didDismissInterstitial!(CBLocationLevelStart)
delegate?.didCloseInterstitial!(CBLocationLevelStart)
delegate?.didDisplayInterstitial!(CBLocationLevelStart)
}
The watchAd function is a button, and when I press it the ad runs, but none of the actions in the appDelegate file run once the ad is completed/dismissed/closed.
I've searched StackOverflow and the Chartboost help sections and messaged Chartboost support but I'm struggling to find where I've gone wrong.
I have an application that needs to interact with peripherals when the app enters a suspended or terminated state. I've added the bluetooth-central to the Info.plist and Capabilities (image) but after i connect to a peripheral it doesn't fire any of the delegate methods while running in the background, but as soon as the app enters the foreground the delegate methods are called! I've also set up CBCenteralManager state restoration
manager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: CoreBluetoothRestorationKey])
let ids = [CBUUID(string: ServiceUUID)]
manager.scanForPeripheralsWithServices(ids, options: nil)
manager.connectPeripheral(peripheral, options: nil)
I've been digging around the internet for hours and haven't found anything. Has anyone had a similar situation before? Any tips? Thanks!
edit: code in context:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let bluetoothManager = CoreBluetoothObserver()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}
}
class CoreBluetoothObserver: NSObject {
let manager: CBCentralManager
override init() {
manager = CBCentralManager(delegate: nil, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: CoreBluetoothRestorationKey])
super.init()
manager.delegate = self
}
}
the CoreBlueToothObserver() initializes CBCenteralManager in its init method and sets self to its delegate. I would assume CoreBlueToothObserver() would be around for the lifetime of the app and not need to be re-initalized in didFinishLaunchingWithOptions? or maybe i need to recreate a CBCenteralManager and inject it in didFinishLaunchingWithOptions? Just stumped as to whats happening.
With the help from #Paulw11 this worked
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bluetoothManager: CoreBluetoothObserver!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
bluetoothManager = CoreBluetoothObserver()
return true
}
}
app is now receiving the delegate methods!
I have integrated all the chartboost the from https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration
but I'm keep getting these 18 errors in my chartboost.h file.
http://i.stack.imgur.com/s7Xek.png
I'm not sure if I made my AppDelegate.swift correct to integrate swift?
class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let kChartboostAppID = "559f1b52c909a64f054eb563";
let kChartboostAppSignature = "41ad09b1bd90bbf3b3712d9530f45daff3fbd04f";
Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self)
Chartboost.setShouldRequestInterstitialsInFirstSession(false)
return true
}
func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{
}
func didDismissInterstitial(location :String! )
{
if(location == CBLocationHomeScreen)
{
Chartboost.cacheInterstitial(CBLocationMainMenu)
}
else if(location == CBLocationMainMenu)
{
Chartboost.cacheInterstitial(CBLocationGameOver)
}
else if(location == CBLocationGameOver)
{
Chartboost.cacheInterstitial(CBLocationLevelComplete)
}
else if(location == CBLocationLevelComplete)
{
Chartboost.cacheInterstitial(CBLocationHomeScreen)
}
}
please help i have been stuck here for a while now please can you help?
I had the same the problem. I brought the entire Chartboost folder into my project instead of just the framework. Go into the folder and delete ChartboostExample. There's an example Xcode project in there that seems to causing weird things to happen.
I have some problem for developing iOS app with libmosquitto
in my code
AppDelegate.swift
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MosquittoClientDelegate{
var window: UIWindow?
var client: MosquittoClient?
func didPublish(messageId: UInt) {
println( "didPublish \(messageId)" )
}
func didReceiveMessage(mosq_msg: MosquittoMessage!) {
println( "didReceiveMessage [ \(mosq_msg.mid)-\(mosq_msg.topic) ] \(mosq_msg.payload)" )
}
func didDisconnect() {
println( "didDisconnect" )
}
func didConnect(code: UInt) {
println( "didConnect \(code)" )
if code == UInt(MOSQ_ERR_SUCCESS.value){
client?.subscribe("sample", withQos: 1)
}
}
func didSubscribe(messageId: UInt, grantedQos qos: [AnyObject]!) {
println( "didSubscribe" )
}
func didUnsubscribe(messageId: UInt) {
println( "didUnsubscribe \(messageId)" )
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
client = MosquittoClient(clientId: "qq")
client?.host = "stick.coffee"
client?.port = 1883
client?.delegate = self
client?.connect()
return true
}
}
This working what i think except when app is exited.
I want receiveMessage even if app is exited.
and I founded there are some mode for background.
Audio and AirPlay
Location updates
Voice over IP
Newsstand downloads
External accessory communication
Uses Bluetooth LE accessories
Acts as Bluetooth LE accessory
Background fetch
Remote Notification
what is best mode for me?
Or is there some example for this stub?
Yep,
I found out there is no method for background running.
but voip can run in background if no need for uploading AppleStore.
so I implements with voip.