Do we have any flutter/native iOS plugins to get the network time during offline mode? Or Is there any option to track the date time automatically settings in iOS device?
If you want to get datetime from device , U can use :
import 'package:intl/intl.dart';
main() {
static final DateTime now = DateTime.now();
static final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(now);
print(formatted); // something like 2013-04-20
}
If you want to fetch date time from internet you must enable internet in your device and Use this package to get date time from internet.
https://pub.dev/packages/ntp
Related
I am currently working on a device and it sends data to Firebase. Unfortunately, I am unable to send the correct time and date.
CONVERT TIME INT TO STRING
I tried setting the time but it ignores the changes.
AT+CLTS=1 should enable network time sync.
AT+CLTS? will check if it is set.
AT&W should save the setting in permanent memory.
AT+CCLK? should display the correct time in the end.
SET TIME AND NETWORK TIME NOT WORKING
The AT&W command most likely does not save gsm network settings .
String arguments to at commands must be enclosed with double quotes, e.g. AT+CCLK="...".
Now I am deveoping in app purchase in iOS using flutter, but the in app purchase did not support debugging on simulator, so I have to package my app and install in real device and test in app purchase, but the problem is the package take me so much time. And I could not see the log and code workflow so I did not know where is going wrong. So I have to tweak my code and package the apk file(the ci may take me hours) again and again. It make me crazy, is it possible to show the log or let me debbuging in simulator when develop in app purchase in iOS?
how to see the log? I write a rest api and send log info to the server side.
static Future<void> logger(String restLog) async {
RestLogModel restLogModel = RestLogModel();
restLogModel.message = restLog;
Map jsonMap = restLogModel.toMap();
try {
final response = await RestClient.postHttp( "/post/logger/v1/log", jsonMap);
if (response.statusCode == 200 &&
response.data["statusCode"] == "200") {
Map channelResult = response.data["result"];
if (channelResult != null) {
// Pay attention: channelResult would be null sometimes
String jsonContent = JsonEncoder().convert(channelResult);
}
} else {
AppLogHandler.logError(RestApiError('Item failed to fetch.'),
JsonEncoder().convert(response));
}
} on Exception catch (e) {
}
}
It works fine. But every time I change the code, I have to repackage the code and install in real device to verify the change, is there anyway to make it easy? like debugging in app purchase in an emulator?
You can use OS Logs to capture the log statements in the MAC Console app and filter the logs by your category
import os.log
extension OSLog {
private static var subsystem = Bundle.main.bundleIdentifier!
/// Logs the view cycles like viewDidLoad.
static let viewCycle = OSLog(subsystem: subsystem, category: "viewcycle") }
I want to set count down timer in swift. I have an option is to get current time is Date() but this method is giving wrong date time when my device time set wrong.
Is it possible to get exact current UTC time in swift, so I will set count down timer with exact time remaining.
Thanks.
The Date class doesn't have a timezone, it's just a "point int the time line" that's the same for all the timezones. When you use a DateFormatter to convert a date to a string (or a string to a date) you can specify the timezone like this:
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
If you cannot trust the device date you will have to use a NTP service like this:
https://github.com/instacart/TrueTime.swift
https://github.com/jbenet/ios-ntp
Get Date and Time from Apple Server
Many times, I have faced the same issue if the user changed his current time then lot's of logic will disturb, Unfortunately, no luck because of Date() always returns your device date.
In well-known game Candy crush, We can not play it for a specific time if my points got over, But if I change device time to feature time then everything will be unlocked. This is the best example of your problem.
You can use below-given web service or your web service to achieve your requirements. Below are some
free API's which provides date and time.
Geonames
Timezonedb
TrueTime
In addition to other answers, you can write an extension for Date class to get formatted Data in specific TimeZone to make it as utility function for future use. Like
extension Date {
func dateInTimeZone(timeZoneIdentifier: String, dateFormat: String) -> String {
let dtf = DateFormatter()
dtf.timeZone = TimeZone(identifier: timeZoneIdentifier)
dtf.dateFormat = dateFormat
return dtf.string(from: self)
}
}
Now you can call it like
Date().dateInTimeZone(timeZoneIdentifier: "UTC", dateFormat: "yyyy-MM-dd HH:mm:ss");
Few days ago, I just updated my firebase pod to the latest version, and in my debugging area, I got message that said that I have to update from timestamp data type to Date (something like that, I forget actually).
and I also have to change the DB settings like below
let db = Firestore.firestore()
let settings = db.settings
settings.areTimestampsInSnapshotsEnabled = true
db.settings = settings
after add the code above, the error message in my debugging area in Xcode disappears.
As far as I remember, I also had to change the data type in my client from Timestamp to Date data type, I haven't changed this because the error message in my debugging area in Xcode have disappeared.
As a result, I get not correct Date in my app.
Could you please share again the conversion step from TimeStamp to Date ? because as far as I remember I had to do some steps to follow. I can't find it in the firebase documentation.
Thank you very much :)
This is the message from the debugger
The behavior for system Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
let db = Firestore.firestore()
let settings = db.settings
settings.areTimestampsInSnapshotsEnabled = true
db.settings = settings
With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example:
// old:
let date: Date = documentSnapshot.get("created_at") as! Date
// new:
let timestamp: Timestamp = documentSnapshot.get("created_at") as! Timestamp
let date: Date = timestamp.dateValue()
Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
I downloaded the Smasthag demo app from course's site. Project builds fine (after small changes in Twitter, TwitterRequest etc. classes, because I use the latest Xcode 7b4) and works fine on simulator (I also had to add NSAppTransportSecurity key to info.plist), but not on a device - it doesn't fetch tweets . I tested it on both iPhone 6 with iOS 9 Public Beta and iPad 2 with iOS 8.4. Moreover, when app is running in the simulator and I change hashtag to search, whole tableView reloads with new tweets, but in the console I get this:
2015-07-23 03:24:15.560 Smashtag[25991:4344251] _BSMachError: (os/kern) invalid capability (20)
2015-07-23 03:24:15.560 Smashtag[25991:4344251] _BSMachError: (os/kern) invalid name (15)
App still runs fine, but this error bugs me. I couldn't fine anything about this _BSMachError in google (just one lonely Indonesian tweet). I can't also get why app doesn't fetch tweets on a device.
This seems to be an iOS 9 Beta bug. It definitely is related to presentation and dismissal of UIKeyboard (the system one). And, at that it doesn't happen all the time.
It's harmless, just annoying. The bug will probably be resolved in the next beta since its in a core system object.
To fix this issue you should set locale to en_US.
Change the private extension asTwitterDate in Tweet.swift to the following to fix issue on non en_US devices.
...
private extension String {
var asTwitterDate: NSDate? {
get {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
let createdAt = dateFormatter.dateFromString(self)
return createdAt
}
}
}
After this your application should load and show all data correctly.
You will need to add NSAppTransportSecurity as a dictionary and as the first child should be a bool named NSAllowsArbitraryLoads set to YES. Note that this opts out of NSAppTransportSecurity feature.
See the App Transport Security configuration notes here. Note that this documentation is brand new and has an error in it, if you want to opt out completely. The error is that the NSAllowsArbitraryLoads key isn't shown as a direct child of NSAppTransportSecurity.
Ideally what you should do is set the appropriate whitelisted domains and security settings.
https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html
I meet the same problem since I switch the keyboard form the system keyboard to self-defined keyboard.However it doesn`t affect my app running.
If there are any opaque attribute for any components in that control, just remove and it and use hidden attribute.
Example:
//invisibleTextView.alpha = 0.0f;
invisibleTextView.hidden = YES;