I am Using Firebase phone number login authentication All things are perfect
1) Provisioning profile
2) certificate
3) Signing methods Enable
4) Project setting with .12 file
5) everything should perfect
Issue
When I send mobile number for the OTP using thins method using this code
NSString *phoneNumber = #"+919428936703";
[[FIRPhoneAuthProvider provider]
verifyPhoneNumber:phoneNumber
completion:^(NSString * verificationID,
NSError * error) {
NSLog(#"VARIFICATION CODE %#", verificationID);
NSLog(#"Error %#", error);
if (!error){
}else{
}
}];
Also get call methods
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Pass device token to auth.
[[FIRAuth auth] setAPNSToken:deviceToken type:FIRAuthAPNSTokenTypeSandbox];
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(#"DATA OF AUTH %#", [FIRAuth auth]);
if ([[FIRAuth auth] canHandleNotification:notification]) {
NSLog(#"Handle by Firebase ");
completionHandler(UIBackgroundFetchResultNoData);
return;
}else{
NSLog(#"NOT HANDLE BY FIREBASE %#", notification);
}
}
but then after getting a crash with this error log
-[__NSCFString setFir_authPhoneNumber:]: unrecognized selector sent to instance 0x166388b0
It looks like you're not linking your app with -ObjC linker flag, which is part of the instructions for Integrate without CocoaPods.
setFir_authPhoneNumber: is implemented as a category, thus -ObjC linker flag must be used or the compiled .o from the library won't be linked into your app binary.
Related
I have integrated Firebase cloud messaging in my iOS application without cocoa pods. Firebase analytics is working fine. But FCM token is received on simulator but not real device. On real device I keep getting error
Failed to fetch default token Error Domain=com.firebase.iid Code=501
"(null)"
I have uploaded the .p12 certificates for development and prod on Firebase
I have checked the bundle ID for my app and that on Firebase console
I have Push notification enable on my App ID.
Here is my code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// For iOS 10 data message (sent via FCM)
[FIRMessaging messaging].remoteMessageDelegate = self;
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];
}
- (void)tokenRefreshNotification:(NSNotification *)notification {
// Note that this callback will be fired everytime a new token is generated, including the first
// time. So if you need to retrieve the token as soon as it is available this is where that
// should be done.
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(#"InstanceID token: %#", refreshedToken);
// Connect to FCM since connection may have failed when attempted before having a token.
[self connectToFcm];
// TODO: If necessary send token to application server.
}
- (void)connectToFcm {
// Won't connect since there is no token
if (![[FIRInstanceID instanceID] token]) {
return;
}
// Disconnect previous FCM connection if it exists.
[[FIRMessaging messaging] disconnect];
[[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(#"Unable to connect to FCM. %#", error);
} else {
NSLog(#"Connected to FCM. FCM token - %#", [[FIRInstanceID instanceID] token] );
}
}];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
[self connectToFcm];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[FIRMessaging messaging] disconnect];
NSLog(#"Disconnected from FCM");
}
Please help.
I got solution to my own problem. The device's date and time was incorrect. The second I changed it to current date & time, Firebase started giving me FCM token and got connected properly. I have checked the push notification as well from Firebase Notification Console. It is working in a way better than I imagined.
May be the issue is due the version problem.Actually me also faced the same problem.I got the FCM token on simulator but not on the device.The reason is due to registering the User notifications setting on didFinishLaunchingWithOptions..... We have to check the version on both device and simulator... If both are not same..please check the " [[UIApplication sharedApplication] registerUserNotificationSettings:settings] "
conditions for the current device version... Bcz I restricted this for >= 10 versions in didFinishLaunchingWithOptions....
Hey guys my app works fine if I am using 3.2. On 3.2 I gather the [[FIRInstanceID instanceID] token] and I send a notification from the firebase console. Works great.
However on 3.3 I attempt the same and it gives me a token but never receives the message. I double checked to make sure notification permissions are accepted etc.. But no dice.
edit** upon inspection FirebaseInstanceID 1.0.7 seems to be the culprit here.
Anyone else seeing this problem? Code below
- (void)tokenRefreshNotification:(NSNotification *)notification
{
[[FIRInstanceID instanceID] token]
// Connect to FCM since connection may have failed when attempted before having a token.
[self connectToFcm];
}
- (void)connectToFcm
{
[[FIRMessaging messaging] connectWithCompletion:^(NSError * _Nullable error) {
if (error != nil)
{
NSLog(#"Unable to connect to FCM. %#", error);
}
else
{
NSLog(#"Connected to FCM.");
}
}];
}
How to receive the PhoneGap push notification in ios platform...?
I am using http://admin.pushapps.mobi console for sending a notification , I have configured everything for ios, and used the app token in my javascript file. I had sent a notification from the admin.pushapps.mobi, but it's not reviewing in my app.
I am using the demo given by them..... below is the full link https://github.com/PushAppsService/PhonegapBuildExampleApp
Can anyone please explain where I am wrong ? if there is any other push notification service having PhoneGap documentation, it would be helpful.
You should check 2 things for PushApps to work as expected:
Certificates and provisioning profile matching.
You should verify the your AppDelegate.m contains as mentioned in the wiki:
#import "PushApps.h"
#pragma mark - Push Notifications
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[[PushAppsManager sharedInstance] didRegisterUserNotificationSettings:notificationSettings];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
[[PushAppsManager sharedInstance] handleActionWithIdentifier:identifier forRemoteNotification:userInfo
completionHandler:completionHandler];
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Notify PushApps of a successful registration.
[[PushAppsManager sharedInstance] updatePushToken:deviceToken];
}
// Gets called when a remote notification is received while app is in the foreground.
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo
{
[[PushAppsManager sharedInstance] handlePushMessageOnForeground:userInfo];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// keeps you up to date with any errors during push setup.
[[PushAppsManager sharedInstance] updatePushError:error];
}
Don't use pushapps.mobi give you all limited notification and user plan and after you get more than on milion users then close your account and then tell you if you want return your account more and more money juswsh layer
I get a new iPhone and when i tried to test it with a Xcode project with push notifications , it doesn't get token , always failed to get token , i think this because when i was creating the certificate i didn't mark on the device , now i want to add this device to the testing and get token what i should do ??
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(#"Failed to get token, error: %#", error);
}
For that you should first set Provisioning profile in which you have added your device UDID.
then Add below code to register Pushnotification in device. so when you run your app first time it will ask you for permission .
//Push Noti
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
If you allow then below delegate will be called. and it will give you device token.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *strDeviceToken = [[[[[deviceToken description]stringByReplacingOccurrencesOfString: #"<" withString: #""] stringByReplacingOccurrencesOfString: #">" withString: #""]stringByReplacingOccurrencesOfString:#" " withString: #""]copy];
NSLog(#"%#",strDeviceToken);
}
If you dont allow then below delegate method will be called
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(#"Failed to get token, error: %#", error);
}
Maybe it will help you.
I am newbie to iphone technology,right now i m working with an application where i need to implement push notification.
I followed the link :
http://mobiforge.com/developing/story/programming-apple-push-notification-services#comment-7850
Also,Used the following code :
NSLog(#"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str = [NSString stringWithFormat:#"Device Token=%#",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: #"Error: %#", err];
NSLog(str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
for (id key in userInfo)
{
NSLog(#"key: %#, value: %#", key, [userInfo objectForKey:key]);
}
}
Thing is,when i run the program,i should get device token in the debugger window,as per the code,instead i am getting error like :
" Error in registration. Error: Error
Domain=NSCocoaErrorDomain Code=3010
"remote notifications are not
supported in the simulator"
UserInfo=0x6e055a0
{NSLocalizedDescription=remote
notifications are not supported in the
simulator} "
How should i solve this problem?
Kindly help me out.
Thank you.
Because the simulator doesn't support it... In the example it displays the device identifier in the console. The console is displaying the feedback from the device. It isn't the console that is getting the information, but the device sending the information back. So, just because the console displays information on your Mac doesn't mean your Mac is capable of directly getting that information. Sometimes it must be sent by the device. Try running it on a device.
The error message is self explaining, you should try to debug the app on real device not on the simulator, as push notifications are not supported to be received on the simulators.