Skip to content

Commit

Permalink
apns token signal and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
theromis committed Sep 7, 2024
1 parent 5675c76 commit 1bf9c6f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions platform/ios/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
String apnsToken = String(hexToken.UTF8String);

OS_IOS::get_singleton()->set_apns_token(apnsToken);
}

- (void)onAudioInterruption:(NSNotification *)notification {
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
Expand Down
4 changes: 4 additions & 0 deletions platform/ios/ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class iOS : public Object {
static void _bind_methods();

private:
String _apns_token;
CHHapticEngine *haptic_engine API_AVAILABLE(ios(13)) = nullptr;

CHHapticEngine *get_haptic_engine_instance() API_AVAILABLE(ios(13));
Expand All @@ -56,6 +57,9 @@ class iOS : public Object {
String get_model() const;
String get_rate_url(int p_app_id) const;

void set_apns_token(const String &p_token);
String get_apns_token() const;

iOS();
};

Expand Down
11 changes: 11 additions & 0 deletions platform/ios/ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
ClassDB::bind_method(D_METHOD("supports_haptic_engine"), &iOS::supports_haptic_engine);
ClassDB::bind_method(D_METHOD("start_haptic_engine"), &iOS::start_haptic_engine);
ClassDB::bind_method(D_METHOD("stop_haptic_engine"), &iOS::stop_haptic_engine);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "apns_token"), "set_apns_token", "get_apns_token");
ADD_SIGNAL(MethodInfo("apns_token_changed", PropertyInfo(Variant::STRING, "token")));
};

bool iOS::supports_haptic_engine() {
Expand Down Expand Up @@ -197,4 +199,13 @@
return ret;
}

void iOS::set_apns_token(const String &p_token) {
_apns_token = p_token;
emit_signal(SNAME("apns_token_changed"), p_token);
}

String iOS::get_apns_token() const {
return _apns_token;
}

iOS::iOS() {}
2 changes: 2 additions & 0 deletions platform/ios/os_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class OS_IOS : public OS_Unix {

virtual bool _check_internal_feature_support(const String &p_feature) override;

void set_apns_token(const String &p_token);

void on_focus_out();
void on_focus_in();

Expand Down
4 changes: 4 additions & 0 deletions platform/ios/os_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,8 @@ void register_dynamic_symbol(char *name, void *address) {
}
}

void OS_IOS::set_apns_token(const String &p_token) {
if (ios)
ios->set_apns_token(p_token);
}
#endif // IOS_ENABLED

0 comments on commit 1bf9c6f

Please sign in to comment.