使用方法
[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]
我不太确定参数的要求是什么?什么是授权实体和行动?我还要将苹果的APNS令牌传递给该方法吗?
答案 0 :(得分:6)
示例:
if (![[FIRInstanceID instanceID] token]) {
[[FIRInstanceID instanceID] tokenWithAuthorizedEntity:_gcmSenderId scope:kFIRInstanceIDScopeFirebaseMessaging options:_registrationOptions handler:^(NSString * _Nullable token, NSError * _Nullable error) {
// Fetch the token or error
}];
}
答案 1 :(得分:1)
你可以这样做。
[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd];
[[FIRInstanceID instanceID] tokenWithAuthorizedEntity:gcmSenderID scope:kFIRInstanceIDTokenRefreshNotification options:nil handler:^(NSString * _Nullable token, NSError * _Nullable error) {
NSLog(@"GCM Registration token = %@",token);
NSLog(@"GCM Registration error = %@",error);
}];
答案 2 :(得分:0)
Swift
的版本(基于@HeadOnn的answer):
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
Messaging.messaging().setAPNSToken(deviceToken, type: .prod) // may be excess
guard let plistPath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
let options = FirebaseOptions(contentsOfFile: plistPath)
else { return }
InstanceID.instanceID().token(withAuthorizedEntity: options.gcmSenderID,
scope: InstanceIDScopeFirebaseMessaging,
options: ["apns_token": deviceToken])
{ (token, error) in
// handle token and error
}
}