How to setup Firebase on IOS from a view controller(not AppDelegate)?

Environment

  • Xcode version: 9.4.1
  • Firebase SDK version: 5
  • Firebase Component: Messaging

Problem

I am trying to integrate Firebase messaging in IOS. My objective is to handle data messages both when app is in foreground and background.

Followed example mainly from here https://firebase.google.com/docs/cloud-messaging/ios/client and some SO.

I have the following three main methods that sets up Firebase. My two main requirements are to handle token changes and process data messages.

- (void)initFirebase{
[FIRApp configure];

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
    printf("n#B initFirebase.IOS 9");
    UIUserNotificationType allNotificationTypes =
    (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
    UIUserNotificationSettings *settings =
    [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
    // iOS 10 or later
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
    printf("n#B initFirebase.IOS 10+");
    UNAuthorizationOptions authOptions =
    UNAuthorizationOptionAlert
    | UNAuthorizationOptionSound
    | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
    }];

    // For iOS 10 display notification (sent via APNS)
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    // For iOS 10 data message (sent via FCM)
    [FIRMessaging messaging].delegate = self;
#endif
}

[[UIApplication sharedApplication] registerForRemoteNotifications];
// NSLog(@"#B initFirebase.fir token is %@",[[FIRInstanceID instanceID] token]);
printf("n#B initFirebase. token: %s", [[[FIRInstanceID instanceID] token] UTF8String]);//token is null here
}

// [START refresh_token]
//called everytime token changes. must register
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
printf("n#B didReceiveRegistrationToken. token: %s", [fcmToken UTF8String]);
//NSLog(@"FCM registration token: %@", fcmToken);
// Notify about received token.
NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
[[NSNotificationCenter defaultCenter] postNotificationName:
 @"FCMToken" object:nil userInfo:dataDict];
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
// [END refresh_token]

//called everytime a message is received. must call custom message handler
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{
printf("n#B application  didReceiveRemoteNotification message:");
//NSLog(@"#B received notification");
//handle the notification here
}

When initFirebase is called from AppDelegate.m ‘didFinishLaunchingWithOptions’, it works perfectly. Token is set. Messages are received.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[self initFirebase];

return YES;
}

However, my requirement is to setup Firebase only when user selects an option from a setting.

When I call the ‘initFirebase’ code after the button is clicked only ‘didReceiveRegistrationToken’ is called.

Messages are not received at all. ‘didReceiveRemoteNotification’ never gets invoked.

Can Firebase not be initialized from a controller upon user action? What is the correct way to achieve this?

All topic

Rebooting MAAS Controller

I have a small cluster of 9 servers (one of which is the rack controller) all managed under MAAS.
I have been able to provision a server and been using it for a while. Now, I am not able to login to the controller (not through its web interface neither through sshing to it). Even directly logging into the controller machine is impossible, and it needs to be restarted.

My question is: will rebooting the controller cause any issues to the current provisioned servers in the cluster? I have looked at the documentation, but it doesn’t specify what the cluster status would look like in the case of rebooting the controller.

All topic

Picklist value is passing null value to controller class

Here is my controller class code:

public String pSortedBy { get; set; }


    Public List getSortOptions() {
    List SortOptions = new List();
    SortOptions.add(new SelectOption('Employee__r.Name','--Select print sort order--'));
    SortOptions.add(new SelectOption('Employee__r.Name','Employee Name'));
    SortOptions.add(new SelectOption('Employee__r.Local_Employee_Number__c','Local Employee Number'));

    return SortOptions;
}

Public List  LoadEmployeeAttendanceToPrint() {
    string sQuery;
    sQuery = 'SELECT Employee__r.Name, Employee__r.Local_Employee_Number__c FROM Employee_Attendance_Detail__c ORDER BY ' ;

    sQuery += pSortedBy;

    lstEmployeesAttendanceToPrint = new List ();
    lstEmployeesAttendanceToPrint = Database.query(sQuery);
    return lstEmployeesAttendanceToPrint;

    }

Here is the visual force page where I have my picklist.


                
  

I’m passing the picklist value to the SOQL as a sort ORDER BY field. I seem to be getting only null values. I’m a Visual Force Error: unexpected token: ‘null’
What am I doing wrong?

All topic

Stacking adc’s when making an midi controller ( lots of potmeters)

I’m making a midi controller with the Arduino uno. It contains approximately 50 analog inputs with potentiometers. I have enough MCP3008 adc’s here but I have no idea how I connect 2 or more adc’s to the Arduino so that I can read 50. How do you stack adc’s?

All topic

Controller file was loaded but class does not exist in localhost

i am new in magento

When i have setup my magento 1.9.0 website in local then after i am facing one error message during check out So can anyone please help me

a:5:{i:0;s:51:”Controller file was loaded but class does not exist”;i:1;s:873:”#0 E:samhtdocsmytheme01includessrc__default.php(28528): Mage::exception(‘Mage_Core’, ‘Controller file…’)

1 E:samhtdocsmytheme01includessrc__default.php(28496): Mage_Core_Controller_Varien_Router_Standard->_includeControllerClass(‘E:Chetanhtdoc…’, ‘WCL_CustomCheck…’)

2 E:samhtdocsmytheme01includessrc__default.php(28383): Mage_Core_Controller_Varien_Router_Standard->_validateControllerClassName(‘WCL_CustomCheck…’, ‘index’)

3 E:samhtdocsmytheme01includessrc__default.php(27971): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))

4 E:samhtdocsmytheme01includessrc__default.php(30837): Mage_Core_Controller_Varien_Front->dispatch()

5 E:samhtdocsrolsonappMage.php(684): Mage_Core_Model_App->run(Array)

6 E:samhtdocsrolsonindex.php(87): Mage::run(”, ‘store’)

7 {main}”;s:3:”url”;s:151:”/mytheme01/checkout/cart/add/uenc/aHR0cDovL2xvY2FsaG9zdC9yb2xzb24vY2xhbXBzLWNyYW1wcy8zcGMtZy1jbGFtcC1zZXQuaHRtbA,,/product/7899/form_key/RGCx0UYdMYYYhd8U/”;s:11:”script_name”;s:17:”/mytheme01/index.php”;s:4:”skin”;s:7:”default”;}

All topic

ASP.NET core return Bad object from controller

I have repo method, that update entry in database. Here is code from repo method

 public async Task UpdateProfile(string email, string firstname, string lastname, DateTime birthday)
    {
        string result;
        var user = _context.AspNetUsers.Where(x => x.Email == email).FirstOrDefault();
        user.FirstName = firstname;
        user.LastName = lastname;
        user.Birthday = birthday;
        await _context.SaveChangesAsync();
        result = "Updated";
        return result;
    }

And here is how I call it from controller

[HttpPost]
    public JsonResult UpdateProfile([FromBody] ProfileViewModel profile)
    {
        var result = _profile.UpdateProfile(profile.Email, profile.FirstName, profile.LastName, profile.Birthday);
        return Json(result);
    }

But in postman I see Bad object, but entry is updated.

Why I get this and how I can fix this?

Thank’s for help.

All topic

Windows 2012 Domain Controller NETLOGON error

We have Sonicwall firewall user authentication System active since last two months.
We have Windows 2012 Active directory server setup with around 1400 user account created.
These accounts were created by using following PowerShell scripts

Import-Module ActiveDirectory 
#Import CSV 
$csv = @() 
$csv = Import-Csv -Path C:UsersAdministratorDesktop"College User Ac Password   Details"FEcivil.csv
FOREACH ($Person in $csv) {
  $name = $Person.UserName
  $displayname = $Person.Name
  $path = "OU=here,DC=comp,DC=com"
  $password = $Person.Password
  $enabled = $True
  $changePW = $False
  $description="CIVIL"
  new-ADUser -SamAccountName $name -Name $name -Description $description -DisplayName $displayname -Path $path -AccountPassword (ConvertTo-SecureString $password -AsPlainText -force) -Enabled $enabled -ChangePasswordAtLogon $changePW -PassThru

}

Above script reads an CSV file with username and passwords and create user accounts on Active Directory.

But since today we are facing issue during authentication process.
We are unable to logon to Directory server. When Sonicwall firewall tries to authenticate an user, it logged-out same user.
When I checked Event logger on Windows Active Directory server it shows following message.

 The dynamic registration of the DNS record 'ForestDnsZones.comp.com. 600 
 IN A 192.168.0.12' failed on the following DNS server:  

 DNS server IP address: (removed)
 Returned Response Code (RCODE): 5 
 Returned Status Code: 9017  

 For computers and users to locate this domain controller, this record must be registered in DNS.  

 USER ACTION  
 Determine what might have caused this failure, resolve the problem, and initiate   
 registration of the DNS records by the domain controller. To determine what might have 
 caused this failure, run DCDiag.exe. To learn more about DCDiag.exe, see Help and 
 Support Center. To initiate registration of the DNS records by this domain  
 controller, run 'nltest.exe /dsregdns' from the command prompt on the domain 
 controller or restart Net Logon service. Or, you can manually add this record to DNS,
 but it is not recommended.  

 ADDITIONAL DATA 
 Error Value: DNS bad key.

Above log entry talks about DNS issue. But I did non configured any DNS server on this machine.Authentication was working fine for last two months , but suddenly from today we are facing above issue.
Kindly help me out in resolving this issue.

EDIT1

Getting following warning in DNS Server Log

The DNS server is waiting for Active Directory Domain Services (AD DS) to signal that the initial synchronization of the directory has been completed. The DNS server service cannot start until the initial synchronization is complete because critical DNS data might not yet be replicated onto this domain controller. If events in the AD DS event log indicate that there is a problem with DNS name resolution, consider adding the IP address of another DNS server for this domain to the DNS server list in the Internet Protocol properties of this computer. This event will be logged every two minutes until AD DS has signaled that the initial synchronization has successfully completed.

All topic

Get Component item from Controller Rendering

I have created a controller rendering and from the controller, I am trying to get the item of the component itself, but I’m getting two different results depending on whether I’m in my dev environment or on a QA server.

In my dev, the controller gets the component item when I use RenderingContext.Current.Rendering.Item but on the QA server, it’s returning the page item instead. I have also tried RenderingContext.Current.ContextItem and Sitecore.Context.Item on the QA server and I get the same result.

I have used both in the past without a problem, but I am flummoxed as to why neither is returning the correct item in this context.

All topic

Xbox one wireless controller keeps turning off after 3-4 seconds (Windows 10)

I recently began having this issue where the controller turns itself off after being on and connected for 3-4 seconds and I have had this controller for 4 months now. I don’t think it’s a battery issue but the controller works fine when it’s being plugged in (USB).

I have tried updating the firmware using the Xbox accessories app but it says I am not assigned and I need to plug it in to configure the controller.

Can this be solved? Thanks!

All topic

hp dl380 g5 with p400 controller and raid 6 mode performance problems

i just want to ask you if that’s an normal speed for an hp dl380 g5 Server with an raid6 (5x HGST 7200rpm 1TB SATA Drives) and no battery. I cant understand that real time speed. can someone explain me a bit please to understand how that raid6 works and why dd Shows me 1 time the real speed and 1 time the fake wit over 600MB and just 3s?

by the way. i updated all server firmwares P44 runs with 7.22 and so on. it’s an Debian 9.4
thx and br

root@srv:/home/root# time sh -c "dd if=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-1.iso of=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-9.iso bs=512k count=4000; sync"
4000+0 Datensätze ein
4000+0 Datensätze aus
2097152000 Bytes (2,1 GB, 2,0 GiB) kopiert, 285,634 s, 7,3 MB/s

real    5m48,305s
user    0m0,008s
sys     0m4,280s

root@srv:/home/xedex# time sh -c "dd if=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-1.iso of=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-10.iso bs=1024k count=4000; sync"
2228+1 Datensätze ein
2228+1 Datensätze aus
2336243712 Bytes (2,3 GB, 2,2 GiB) kopiert, 338,13 s, 6,9 MB/s

real    5m58,860s
user    0m0,000s
sys     0m4,240s

root@srv:/home/root# time sh -c "dd if=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-1.iso of=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-11.iso bs=512k count=4000; sync"
4000+0 Datensätze ein
4000+0 Datensätze aus
2097152000 Bytes (2,1 GB, 2,0 GiB) kopiert, 3,19221 s, 657 MB/s

real    5m18,637s
user    0m0,008s
sys     0m3,184s

root@srv:/home/root# time sh -c "dd if=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-1.iso of=/media/root/RAID6_34567/debian-9.5.0-amd64-DVD-12.iso bs=512k count=4000; sync"
4000+0 Datensätze ein
4000+0 Datensätze aus
2097152000 Bytes (2,1 GB, 2,0 GiB) kopiert, 3,17891 s, 660 MB/s

real    5m15,798s
user    0m0,012s
sys     0m3,176s

All topic