Initialising FIRApp in iOS without GCMSenderID

640 views
Skip to first unread message

anu...@vserv.com

unread,
Nov 1, 2016, 12:11:06 AM11/1/16
to Firebase Google Group
I'm initialising FIRApp in my iOS App using the configureWithOptions api as follows:


FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"x:xxxxxxx:ios:xxxxxxx" bundleID:nil GCMSenderID:@"xxxxxxxx" APIKey:nil clientID:nil trackingID:nil androidClientID:nil databaseURL:@"https://xxxxxx.firebaseio.com" storageBucket:nil deepLinkURLScheme:nil];


[FIRApp configureWithOptions:options];



This is being done in order to dynamically instantiate it with minimal required parameters obtained through the app's server without having the Firebase plist file added to the app's Xcode project. However, if I omit GCMSenderID by setting it as nil, the app gives an exception when running it. Why is the GCMSenderID required in the code above & is there any way to work without it? Kindly let me know. Thanks in advance!


*************************

CONFIDENTIALITY CAUTION

This communication (including any accompanying documents) is intended only for the use of the addressee(s) and contains PRIVATE AND CONFIDENTIAL information. Unauthorized reading, dissemination, distribution or copying of this communication is prohibited. If you have received this communication in error, please notify us immediately by e-mail and promptly destroy the original communication. Please do not copy it or use it for any other purposes, or disclose its contents to any other person. Unless stated to the contrary, any opinions or comments are personal to the writer and do not represent the official view of the Company. In case where it represents our official view, it needs to be revalidated and is subject to the terms of our engagement.

Thank you for your co-operation.

*************************

Ian Barber

unread,
Nov 1, 2016, 6:08:00 PM11/1/16
to Firebase Google Group
Just to clarify, are you including the Firebase/Messaging pod in your project? It shouldn't require the value otherwise, but please let us know what error you are seeing. 

Otherwise, your GCM sender ID corresponds to your project number, so you can likely just pass that and make it happy. 

anu...@vserv.com

unread,
Nov 2, 2016, 10:48:18 AM11/2/16
to Firebase Google Group
Hello Ian,
Thank you for your reply. I've manually added the Firebase frameworks, not via pods. The frameworks have been added based on the instructions given in the readme file (see screenshot) of the Firebase sdk zip file. Please see the additional attached screenshot of the frameworks added (including dependencies) into the project. I do not see any messaging pod/framework being added. Kindly advise further steps.
Thank you for your time.
Screen Shot 2016-11-02 at 9.14.53 AM.png
Screen Shot 2016-11-02 at 9.14.06 AM.png

anu...@vserv.com

unread,
Nov 2, 2016, 10:48:18 AM11/2/16
to Firebase Google Group
Below is the exception encountered when setting GCMSenderID as nil:

2016-11-02 09:21:20.036 FirebaseObjCDemo[725] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.

2016-11-02 09:21:20.072 FirebaseObjCDemo[725:20] <FIRAnalytics/INFO> Firebase Analytics v.3501000 started

2016-11-02 09:21:20.077 FirebaseObjCDemo[725:20] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/Y0Yjwu)

2016-11-02 09:21:20.100 FirebaseObjCDemo[725] <Debug> [Firebase/Core][I-COR000018] Already sending logs.

2016-11-02 09:21:20.108 FirebaseObjCDemo[725:11462] *** Terminating app due to uncaught exception 'com.firebase.instanceid', reason: 'Could not configure Firebase InstanceID.'

*** First throw call stack:

(

 
0   CoreFoundation                      0x0000000110560c65 __exceptionPreprocess + 165

 
1   libobjc.A.dylib                     0x000000010fde0bb7 objc_exception_throw + 45

 
2   CoreFoundation                      0x0000000110560b9d +[NSException raise:format:] + 205

 
3   FirebaseObjCDemo                    0x000000010f637a62 -[FIRInstanceID(FIRApp) configureInstanceIDWithOptions:app:] + 498

 
4   FirebaseObjCDemo                    0x000000010f6377ba +[FIRInstanceID(FIRApp) didReceiveConfigureSDKNotification:] + 273

 
5   CoreFoundation                      0x000000011053054c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12

 
6   CoreFoundation                      0x000000011042ea04 _CFXNotificationPost + 2484

 
7   Foundation                          0x000000010f937968 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66

 
8   FirebaseObjCDemo                    0x000000010f5f22cd +[FIRApp sendNotificationsToSDKs:] + 296

 
9   FirebaseObjCDemo                    0x000000010f5f110b +[FIRApp configureDefaultAppWithOptions:sendingNotifications:] + 341

 
10  FirebaseObjCDemo                    0x000000010f5f0e72 +[FIRApp configureWithOptions:] + 90

 
11  FirebaseObjCDemo                    0x000000010f53e2b6 -[AppDelegate application:didFinishLaunchingWithOptions:] + 262

 
12  UIKit                               0x0000000110d24748 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 240

 
13  UIKit                               0x0000000110d25357 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2540

 
14  UIKit                               0x0000000110d2819e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349

 
15  UIKit                               0x0000000110d27095 -[UIApplication workspaceDidEndTransaction:] + 179

 
16  FrontBoardServices                  0x000000011467b5e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21

 
17  CoreFoundation                      0x000000011049441c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12

 
18  CoreFoundation                      0x000000011048a165 __CFRunLoopDoBlocks + 341

 
19  CoreFoundation                      0x0000000110489f25 __CFRunLoopRun + 2389

 
20  CoreFoundation                      0x0000000110489366 CFRunLoopRunSpecific + 470

 
21  UIKit                               0x0000000110d26b02 -[UIApplication _run] + 413

 
22  UIKit                               0x0000000110d298c0 UIApplicationMain + 1282

 
23  FirebaseObjCDemo                    0x000000010f53e54f main + 111

 
24  libdyld.dylib                       0x0000000112a7e145 start + 1

 
25  ???                                 0x0000000000000001 0x0 + 1

)

libc
++abi.dylib: terminating with uncaught exception of type NSException



It works fine if I set the GCMSenderID but I'd like to do without it in order to have it dynamically setup.

On Wednesday, November 2, 2016 at 3:38:00 AM UTC+5:30, Ian Barber wrote:

Ian Barber

unread,
Nov 2, 2016, 12:25:10 PM11/2/16
to fireba...@googlegroups.com
Ah, thanks that helps explain! I'd completely forgotten that Firebase Analytics uses Instance Id, which uses the GCM sender ID as part of its options, hence why it is required. We should likely validate that in FIROptions - I'll raise an issue for that. 

--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/v-mXARP3uK8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/5a5f7f9c-c5c8-4e35-9782-ca920856f77e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

anu...@vserv.com

unread,
Nov 3, 2016, 12:21:30 AM11/3/16
to Firebase Google Group
Thank you for replying. So is there no way but to set the actual GCMSenderID in order for Firebase to function correctly? Workarounds?
Please confirm.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Ian Barber

unread,
Nov 3, 2016, 12:19:58 PM11/3/16
to fireba...@googlegroups.com
That's correct, no work arounds as far as I am aware.

To unsubscribe from this group and all its topics, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

anu...@vserv.com

unread,
Nov 4, 2016, 11:25:53 AM11/4/16
to Firebase Google Group
Ok. Also found out that if I try to use FIRAuth and its methods after initialising FIRApp, it doesn't work unless I've initialised FIRApp by setting the APIKey as well !
So as it stands, I need to set the app id, gcm sender id, database url and api key compulsorily in order to be able to work with FIRAuth and subsequently, FirebaseDatabase.

Ian Barber

unread,
Nov 4, 2016, 11:52:47 AM11/4/16
to Firebase Google Group
Yep, the API key is used for auth, and I might be right in saying crash reporting. There is also a Storage URL used for Firebase storage, a client ID which can be used for Google Sign In, and some fields for appinvites and dynamic links. 

anu...@vserv.com

unread,
Nov 7, 2016, 10:27:39 AM11/7/16
to Firebase Google Group
Thanks Ian for the info! I have one other question if you could answer it for me here, else I will consider adding a new post.
Q. If I sign in a user using customToken but I do not perform any firebase operations say for a few hours, does the token expire in this case? Alternately, how is token refresh to be done ?

Ian Barber

unread,
Nov 7, 2016, 11:17:58 AM11/7/16
to fireba...@googlegroups.com
If you sign in with a custom token, it will set up a session that generally doesn't expire (unless something happens to clear the cache or similar). If the session does need to be refreshed, they would need a fresh custom token to sign in with. 

To unsubscribe from this group and all its topics, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Jacob Wenger

unread,
Nov 7, 2016, 12:38:05 PM11/7/16
to fireba...@googlegroups.com
Just to clarify what Ian said, the custom token itself expires after one hour (you can see this by pasting the custom token into https://jwt.io), but if you use it to call signInWithCustomToken(), the session that is created never expires. The Firebase client SDKs handle the token refresh for you under the hood.

Cheers,
Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

anu...@vserv.com

unread,
Nov 29, 2016, 10:20:06 AM11/29/16
to Firebase Google Group
Hi Jacob,
Thank you for the info. We've observed that on app restart after about 1 hour or so, the signInWithCustomToken returns "ERROR_INVALID_CUSTOM_TOKEN".
The usage is such that my app requests my server for a token. The server generates a custom token and stores it in the database at server side and always returns the same token back to the app before the app does a signInWithCustomToken(). However after first time sign in success, if I quit the app say after a short session and restart the app and further attempt a signInWithCustomToken with the previously generated token, an error is observed. It works fine if a new token is generated and used for signIn, however I would like to avoid that overhead.
It seems to me that the Firebase SDK does a sign-out internally somehow. Could you please check & let me know what could be the issue?

2016-11-28 16:20:03.694 Sample[22366:2528104] Firebase auth failure: Error Domain=FIRAuthErrorDomain Code=17000 "The custom token format is incorrect. Please check the documentation." UserInfo=0x7f98c3e26bf0 {NSLocalizedDescription=The custom token format is incorrect. Please check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN}

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Kato Richardson

unread,
Nov 29, 2016, 2:46:45 PM11/29/16
to Firebase Google Group

You shouldn’t call `signInWithCustomToken()` each time the app restarts. The custom JWT token you issue from your server is not the client's long-term authorization token. 

When you call `signInWithCustomToken()`, the JWT is traded for a Firebase Auth ID token. Firebase stores this session and maintains it for you, even when you restart the app.

Instead of trying to authenticate with the custom token on each restart, just monitor auth status. If the user is not authenticated (i.e. the auth session has expired permanently), then you should request a new custom token. Otherwise, they will be signed in automatically and the session can continue with no action on your part.

☼, Kato


To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages