I have a problem in my SwiftUI project, I try to use mobile authentication with firebase, when I put my number and click the button , it is throw an error as a
If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method.
I am still do not understand what I missed?
@State var no = ""
@State var show = false
@State var msg = ""
@State var alert = false
@State var ID = ""
var body : some View{
VStack{
TextField("No",text:self.$no)
NavigationLink(destination: CodeView(show: $show, ID: $ID), isActive: $show)
{
Button {
PhoneAuthProvider.provider().verifyPhoneNumber(self.no, uiDelegate: nil)
{ (ID, err) in
if err != nil{
self.msg = (err?.localizedDescription)!
self.alert.toggle()
return
}
self.ID = ID!
self.show.toggle()
}
} label: {
Text("OK")
.padding()
}
}
} .alert(isPresented: $alert) {
Alert(title: Text("Error"), message: Text(self.msg), dismissButton:
.default(Text("Ok")))
}
}
CodeView:
@State var scode = ""
@State var show = false
@State var msg = ""
@State var alert = false
@State var ID = ""
VStack {
TextField("SMS Code", text: self.$scode)
NavigationLink(destination: HomeView(), isActive:
$show) {
Button {
let credential = PhoneAuthProvider.provider().credential(withVerificationID:
self.ID, verificationCode: self.scode)
Auth.auth().signIn(with: credential) { (res, err) in
if err != nil{
self.msg = (err?.localizedDescription)!
self.alert.toggle()
return
}
UserDefaults.standard.set(true, forKey: "status")
NotificationCenter.default.post(name:
NSNotification.Name("statusChange"), object: nil)
}
} label: {
Text("Next")
.padding()
}
} .alert(isPresented: $alert) {
Alert(title: Text("Error"), message: Text(self.msg),
dismissButton: .default(Text("Ok")))
}
MyApp:
import SwiftUI
import Firebase
@main
struct App: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
ZStack{
ContentView()
}
}
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I have simple chat app, and it is work for image picker, but I have custom image view and it fetch the images from internet, I want to use them instead of the image picker in my phone, but I did not find any solution, is there any idea about it?
struct Home: View {
@State var message = ""
@State var imagePicker = false
@State var imgData: Data = Data(count: 0)
@StateObject var allMessages = Messages()
var body: some View {
ZStack {
VStack {
VStack {
// Displaying Message
ScrollView(.vertical, showsIndicators: true) {
ScrollViewReader { reader in
VStack(spacing: 20) {
ForEach(allMessages.messages) { msg in
ChatBubble(msg: msg)
}
.onChange(of: allMessages.messages) {
value in
if value.last!.myMsg {
reader.scrollTo(value.last?.id)
}}}}}}}
.clipShape(RoundedRectangle(cornerRadius: 35))}
VStack {
HStack(spacing: 15) {
HStack(spacing: 15) {
TextField("Message", text: $message)
Button(action: {
// toggling image picker
imagePicker.toggle()
}) {
Image(systemName: "paperclip.circle.fill")
.font(.system(size: 22))
.foregroundColor(.gray)}
.background(Color.black.opacity(0.06))
.clipShape(Capsule())
if message != "" {
Button(action: {
withAnimation(.easeIn) {
allMessages.messages.append(Message(id: Date(), message: message, myMsg: true, profilePic: "p1", photo: nil))
}
message = ""
}) {
Image(systemName: "paperplane.fill")
.font(.system(size: 22))
.foregroundColor(Color("Color"))
// rotating the image
.rotationEffect(.init(degrees: 45))
.clipShape(Circle())}}}
.padding(.bottom)
.padding(.horizontal)
.background(Color.white)
.animation(.easeOut)
}
.fullScreenCover(isPresented: $imagePicker, onDismiss: {
if imgData.count != 0 {
allMessages.writeMessage(id: Date(), msg: "", photo: imgData, myMsg: true, profilePic: "p1")
}
}) {
ImagePicker(imagePicker: $imagePicker, imgData: $imgData)
}}}}
struct ChatBubble: View {
var msg: Message
var body: some View {
HStack(alignment: .top, spacing: 10) {
if msg.myMsg {
if msg.photo == nil {
Text(msg.message)
.padding(.all)
.background(Color.black.opacity(0.06))
.clipShape(BubbleArrow(myMsg: msg.myMsg))
} else {
Image(uiImage: UIImage(data: msg.photo!)!)
.resizable()
.frame(width: UIScreen.main.bounds.width - 150, height: 150)
.clipShape(BubbleArrow(myMsg: msg.myMsg))
}
Image(msg.profilePic)
.resizable()
.frame(width: 30, height: 30)
.clipShape(Circle())
} else {
Image(msg.profilePic)
.resizable()
.frame(width: 30, height: 30)
.clipShape(Circle())
if msg.photo == nil {
Text(msg.message)
.foregroundColor(.white)
.padding(.all)
.background(Color("Color"))
.clipShape(BubbleArrow(myMsg: msg.myMsg))
} else {
Image(uiImage: UIImage(data: msg.photo!)!)
.resizable()
.frame(width: UIScreen.main.bounds.width - 150, height: 150)
.clipShape(BubbleArrow(myMsg: msg.myMsg))}}}
.id(msg.id)}}
struct RoundedShape: Shape {
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 35, height: 35))
return Path(path.cgPath)
}
}
struct Message: Identifiable, Equatable {
var id: Date
var message: String
var myMsg: Bool
var profilePic: String
var photo: Data?
}
class Messages: ObservableObject {
@Published var messages: [Message] = []
init() {
let strings = ["Hii", "Hello!!", "What's up?", "What Are you doing?", "Nothing, just enjoying quarantine holidays.. you??", "Same :))", "Ohhh", "What about your country?", "Very very bad..", "Ok, be safe.", "Ok", "Bye"]
for i in 0..<strings.count {
// simple logic for two side message View
messages.append(Message(id: Date(), message: strings[i], myMsg: i % 2 == 0, profilePic: i % 2 == 0 ? "p1" : "p2"))
}
}
func writeMessage(id: Date, msg: String, photo: Data?, myMsg: Bool, profilePic: String) {
messages.append(Message(id: id, message: msg, myMsg: myMsg, profilePic: profilePic, photo: photo))
}
}
CustomImageView:
struct CustomImageView: View {
private let threeColumnGrid = [
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
]
var body: some Scene {
LazyVGrid(columns: threeColumnGrid, alignment: .center) {
ForEach(model.imageNames, id: \.self) { item in
GeometryReader { gr in
Image(item)
.resizable()
.scaledToFill()
.frame(height: gr.size.width)
}
.clipped()
.aspectRatio(1, contentMode: .fit)
}
}
}
}
I have a register view and when I complete my register, I want to pass register data in form from WebView, is there any way to do it?
I have a simple app and it has simple properties, like user register to app, and it connect the webview, webview has payment also, but I am search on internet, and many people says like that apps will reject by apple, any idea?
I have a small app and I am using WKWebView for my app, so in WebView I have sign in, when I sign to WebView I have to import image, documents etc to WebView, so I have to use permission in my app, is it possible to apply WKWebView in below code?
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
ZStack{
WebView()
}
}
}
struct WebView: UIViewRepresentable {
func makeUIView(context: Context) -> WKWebView {
WKWebView(frame: .zero)
}
func updateUIView(_ view: WKWebView, context: UIViewRepresentableContext<WebView>) {
let request = URLRequest(url: URL(string: "https://codepen.io/login")!)
view.load(request)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.navigationBarHidden(true)
}
}
When I update my macbook to macOS13 Venture , I have a problem in top right corner, always give alots of notifications , how can I solve it?