-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
urban airship integration support (#164)
* porting connect integrations + urban airship code from obj c * tagging $urban_airship_channel_id with ios or android * decide response integrations using internal names instead of db ids * urban_airship -> urbanairship * fix a crash if the channelID is nil (not sure how it didn't show up in testing earlier)
- Loading branch information
pchien
authored
Dec 11, 2017
1 parent
8e4b37b
commit db9428d
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// ConnectIntegrations.swift | ||
// Mixpanel | ||
// | ||
// Created by Peter Chien on 10/10/17. | ||
// Copyright © 2017 Mixpanel. All rights reserved. | ||
// | ||
|
||
class ConnectIntegrations { | ||
open var mixpanel: MixpanelInstance? | ||
var urbanAirshipRetries = 0 | ||
var savedUrbanAirshipChannelID: String? | ||
|
||
open func setupIntegrations(_ integrations:[String]) { | ||
if integrations.contains("urbanairship") { | ||
self.setUrbanAirshipPeopleProp() | ||
} | ||
} | ||
|
||
func setUrbanAirshipPeopleProp() { | ||
if let urbanAirship = NSClassFromString("UAirship") { | ||
let pushSelector = NSSelectorFromString("push") | ||
if let pushIMP = urbanAirship.method(for: pushSelector) { | ||
typealias pushFunc = @convention(c) (AnyObject, Selector) -> AnyObject! | ||
let curriedImplementation = unsafeBitCast(pushIMP, to: pushFunc.self) | ||
if let push = curriedImplementation(urbanAirship.self, pushSelector) { | ||
if let channelID = push.perform(NSSelectorFromString("channelID"))?.takeUnretainedValue() as? String { | ||
self.urbanAirshipRetries = 0 | ||
if (channelID != self.savedUrbanAirshipChannelID) { | ||
self.mixpanel?.people.set(property: "$ios_urban_airship_channel_id", to: channelID) | ||
self.savedUrbanAirshipChannelID = channelID | ||
} | ||
} else { | ||
self.urbanAirshipRetries += 1 | ||
if self.urbanAirshipRetries <= ConnectIntegrationsConstants.uaMaxRetries { | ||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) { | ||
self.setUrbanAirshipPeopleProp() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
open func reset() { | ||
self.savedUrbanAirshipChannelID = nil | ||
self.urbanAirshipRetries = 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,7 @@ extension UIDevice { | |
} | ||
} | ||
#endif // !os(OSX) | ||
|
||
struct ConnectIntegrationsConstants { | ||
static let uaMaxRetries = 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters