Skip to content

Commit

Permalink
Calling registerForRemoteNotifications when get token
Browse files Browse the repository at this point in the history
  • Loading branch information
timwangdev committed Oct 23, 2018
1 parent 7fe7f05 commit 137fe59
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ios/RNFirebase/messaging/RNFirebaseMessaging.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void)configure {

// Establish Firebase managed data channel
[FIRMessaging messaging].shouldEstablishDirectChannel = YES;

// Set static instance for use from AppDelegate
theRNFirebaseMessaging = self;
}
Expand Down Expand Up @@ -124,6 +124,9 @@ - (void)messaging:(nonnull FIRMessaging *)messaging
}
}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[RCTSharedApplication() registerForRemoteNotifications];
});
}

RCT_EXPORT_METHOD(requestPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
Expand Down Expand Up @@ -154,10 +157,6 @@ - (void)messaging:(nonnull FIRMessaging *)messaging
}];
}
}

dispatch_async(dispatch_get_main_queue(), ^{
[RCTSharedApplication() registerForRemoteNotifications];
});
}

// Non Web SDK methods
Expand Down Expand Up @@ -188,7 +187,7 @@ - (void)messaging:(nonnull FIRMessaging *)messaging
NSDictionary *data = message[@"data"];

[[FIRMessaging messaging] sendMessage:data to:to withMessageID:messageId timeToLive:[ttl intValue]];

// TODO: Listen for send success / errors
resolve(nil);
}
Expand Down Expand Up @@ -267,7 +266,7 @@ - (NSDictionary*)parseFIRMessagingRemoteMessage:(FIRMessagingRemoteMessage *)rem
- (NSDictionary*)parseUserInfo:(NSDictionary *)userInfo {
NSMutableDictionary *message = [[NSMutableDictionary alloc] init];
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];

for (id k1 in userInfo) {
if ([k1 isEqualToString:@"aps"]) {
// Ignore notification section
Expand All @@ -287,9 +286,9 @@ - (NSDictionary*)parseUserInfo:(NSDictionary *)userInfo {
data[k1] = userInfo[k1];
}
}

message[@"data"] = data;

return message;
}

Expand Down

0 comments on commit 137fe59

Please sign in to comment.