2

I use a package pusher_client: ^2.0.0 in Flutter it works without any problem with Android but when run my project on ios simulator I get error in the console.

when I run flutter run I get the following errors, I removed some repeated parts of the error due to content length.


Xcode's output:
↳
    2 warnings generated.
    error: the following command failed with exit code 0 but produced no further output
    CompileC
    /Users/zia/Library/Developer/Xcode/DerivedData/Runner-hdzpmljlvwqzschdvjjsljzxqxtc/Build/Intermediates.noindex/
    Pods.build/Debug-iphonesimulator/location.build/Objects-normal/arm64/LocationPlugin.o
    /Users/zia/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/location-4.3.0/ios/Classes/LocationPlugin.m
    normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'location' from project 'Pods')
    /Users/zia/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_phone_direct_caller-2.1.0/ios/Classes/F
    lutterPhoneDirectCallerPlugin.m:24:22: warning: 'stringByAddingPercentEscapesUsingEncoding:' is deprecated:
    first deprecated in iOS 9.0 - Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always
    uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each
    URL component or subcomponent has different rules for what characters are valid. [-Wdeprecated-declarations]
        number = [number stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                         ^
    In module 'UIKit' imported from /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Target Support
    Files/flutter_phone_direct_caller/flutter_phone_direct_caller-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h:599:1: note:
    'stringByAddingPercentEscapesUsingEncoding:' has been explicitly marked deprecated here
    - (nullable NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc API_DEPRECATED("Use
    -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding,
    and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has
    different rules for what characters are valid.", macos(10.0,10.11), ios(2.0,9.0), watchos(2.0,2.0),
    tvos(9.0,9.0));
    ^
    /Users/zia/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_phone_direct_caller-2.1.0/ios/Classes/F
    lutterPhoneDirectCallerPlugin.m:30:51: warning: 'openURL:' is deprecated: first deprecated in iOS 10.0
    [-Wdeprecated-declarations]
        } else if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]]) {
                                                      ^~~~~~~
                                                      openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Target Support
    Files/flutter_phone_direct_caller/flutter_phone_direct_caller-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:124:1: note: 'openURL:' has been
    explicitly marked deprecated here
    - (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0,
    10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
    ^
    2 warnings generated.
    /Users/zia/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_phone_direct_caller-2.1.0/ios/Classes/F
    lutterPhoneDirectCallerPlugin.m:24:22: warning: 'stringByAddingPercentEscapesUsingEncoding:' is deprecated:
    first deprecated in iOS 9.0 - Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always
    uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each
    URL component or subcomponent has different rules for what characters are valid. [-Wdeprecated-declarations]
        number = [number stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                         ^
    In module 'UIKit' imported from /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Target Support
    Files/flutter_phone_direct_caller/flutter_phone_direct_caller-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h:599:1: note:
    'stringByAddingPercentEscapesUsingEncoding:' has been explicitly marked deprecated here
    - (nullable NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc API_DEPRECATED("Use
    -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding,
    and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has
    different rules for what characters are valid.", macos(10.0,10.11), ios(2.0,9.0), watchos(2.0,2.0),
    tvos(9.0,9.0));
    ^
    /Users/zia/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_phone_direct_caller-2.1.0/ios/Classes/F
    lutterPhoneDirectCallerPlugin.m:30:51: warning: 'openURL:' is deprecated: first deprecated in iOS 10.0
    [-Wdeprecated-declarations]
        } else if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]]) {
                                                      ^~~~~~~
                                                      openURL:options:completionHandler:
    In module 'UIKit' imported from /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Target Support
    Files/flutter_phone_direct_caller/flutter_phone_direct_caller-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.
    2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:124:1: note: 'openURL:' has been
    explicitly marked deprecated here
    - (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0,
    10.0)) NS_EXTENSION_UNAVAILABLE_IOS("");
    ^
    2 warnings generated.
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:61:34:
    warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    public protocol WebSocketClient: class {
                                     ^~~~~
                                               AnyObject
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:282:30:
    warning: 'withUnsafeMutableBytes' is deprecated: use `withUnsafeMutableBytes<R>(_:
    (UnsafeMutableRawBufferPointer) throws -> R) rethrows -> R` instead
                let _ = peerName.withUnsafeMutableBytes { (peerNamePtr: UnsafeMutablePointer<Int8>) in
                                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1326:14:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            data.withUnsafeBytes { _ = CC_SHA1($0, CC_LONG(data.count), &digest) }
                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1327:16:
    warning: 'init(bytes:)' is deprecated: use `init(_:)` instead
            return Data(bytes: digest).base64EncodedString()
                   ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:59:25:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            return try data.withUnsafeBytes { (bytes:UnsafePointer<UInt8>) -> Data in
                            ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:83:29:
    warning: initialization of 'UnsafeMutablePointer<UInt8>' results in a dangling pointer
                strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                            
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:140:14:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            data.withUnsafeBytes { (ptr:UnsafePointer<UInt8>) -> Void in
                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:61:34:
    warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    public protocol WebSocketClient: class {
                                     ^~~~~
                                     AnyObject
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:119:35:
    warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    public protocol WSStreamDelegate: class {
                                      ^~~~~
                         ...
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:282:30:
    warning: 'withUnsafeMutableBytes' is deprecated: use `withUnsafeMutableBytes<R>(_:
    (UnsafeMutableRawBufferPointer) throws -> R) rethrows -> R` instead
                let _ = peerName.withUnsafeMutableBytes { (peerNamePtr: UnsafeMutablePointer<Int8>) in
                                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1326:14:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            data.withUnsafeBytes { _ = CC_SHA1($0, CC_LONG(data.count), &digest) }
                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1327:16:
    warning: 'init(bytes:)' is deprecated: use `init(_:)` instead
            return Data(bytes: digest).base64EncodedString()
                   ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:59:25:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            return try data.withUnsafeBytes { (bytes:UnsafePointer<UInt8>) -> Data in
                            ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:83:29:
    warning: initialization of 'UnsafeMutablePointer<UInt8>' results in a dangling pointer
                strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:83:57:
    note: implicit argument conversion from '[UInt8]' to 'UnsafeMutablePointer<UInt8>' produces a pointer valid
    only for the duration of the call to 'init(_:)'
                strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
                                                            ^~~~~~~
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:83:57:
    note: use the 'withUnsafeMutableBufferPointer' method on Array in order to explicitly convert argument to
    buffer pointer valid for a defined scope
                strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
                                                            ^
...
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/Compression.swift:140:14:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            data.withUnsafeBytes { (ptr:UnsafePointer<UInt8>) -> Void in
                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:61:34:
    warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    public protocol WebSocketClient: class {
                                     ^~~~~
                                     AnyObject
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:119:35:
    warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    public protocol WSStreamDelegate: class {
                                      ^~~~~
     ...                                
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1326:14:
    warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R)
    rethrows -> R` instead
            data.withUnsafeBytes { _ = CC_SHA1($0, CC_LONG(data.count), &digest) }
                 ^
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Starscream/Sources/Starscream/WebSocket.swift:1327:16:
    warning: 'init(bytes:)' is deprecated: use `init(_:)` instead
            return Data(bytes: digest).base64EncodedString()
                   ^
    ld: in
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Sodium/Sodium/libsodium/libsodium-ios.a(libsodium_la-ae
    ad_xchacha20poly1305.o), building for iOS Simulator, but linking in object file built for iOS, for architecture
    arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in dependency order
    warning: Capabilities for Signing & Capabilities may not function correctly because its entitlements use a
    placeholder team ID. To resolve this, select a development team in the Runner editor. (in target 'Runner' from
    project 'Runner')
    /Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment
    target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0
    to 15.2.99. (in target 'leveldb-library' from project 'Pods')


Could not build the application for the simulator.
Error launching application on iPhone 13.

I could not find any related message in the above error This is flutter --version

% flutter --version 
Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

This is how I connect to pusher


import 'package:pusher_client/pusher_client.dart';
...
...

class Messages extends StatefulWidget {
  final Room room;
  final int user;
  const Messages({Key? key, required this.room, required this.user})
      : super(key: key);

  @override
  _MessagesState createState() => _MessagesState();
}

class _MessagesState extends State<Messages> {
  TextEditingController _messageController = TextEditingController();
  PusherClient? pusher;
  Channel? channel;
  List<Message> messages = [];

  @override
  void initState() {
    _initPusher();
    super.initState();
  }

  @override
  void dispose() {
    channel?.unbind('chat-event');
    pusher?.unsubscribe('chat.' + widget.room.id.toString());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Message")),
      body: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            FutureBuilder(
              future: _get(),
              builder: (context, snapshot) {
                if (snapshot.hasData ||
                    snapshot.connectionState == ConnectionState.done) {
                  return Expanded(
                    child: ListView.builder(
                      reverse: true,
                      padding: EdgeInsets.only(top: 12, left: 12, right: 12),
                      shrinkWrap: true,
                      itemCount: messages.length,
                      itemBuilder: (context, index) {
                        return Column(
                          children: [
                            _buildMyMessage(messages[index]) != null
                                ? MyMessageCard(
                                    message: _buildMyMessage(messages[index]))
                                : Container(),
                            _buildFriendMessage(messages[index]) != null
                                ? FriendMessageCard(
                                    message:
                                        _buildFriendMessage(messages[index]))
                                : Container(),
                          ],
                        );
                      },
                    ),
                  );
                } else if (snapshot.hasError) {
                  return Padding(
                    child: Text("Error: ${snapshot.error}"),
                    padding: EdgeInsets.only(top: 8),
                  );
                } else {
                  return Center(
                      child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: circularProgress(context)));
                }
              },
            ),
            Container(
              padding: EdgeInsets.all(5),
              margin: EdgeInsets.all(5),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Expanded(
                    child: SizedBox(
                      height: 55,
                      child: Card(
                        elevation: 2,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(50),
                        ),
                        child: Padding(
                          padding: const EdgeInsets.only(
                              left: 18.0, right: 18.0, top: 3),
                          child: TextFormField(
                            controller: _messageController,
                            decoration: InputDecoration(
                                border: InputBorder.none,
                                isDense: true,
                                hintText: 'Message'),
                          ),
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 55,
                    height: 55,
                    child: Card(
                      color: Tingsapp.primary,
                      elevation: 2,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(50),
                      ),
                      child: InkWell(
                          onTap: () => _send(context),
                          child: Icon(
                            Icons.send,
                            color: Colors.white,
                          )),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  _send(context) async {
    Api api = new Api();
    try {
      var response = await api.post(
        jsonEncode(
          <String, dynamic>{
            'message': _messageController.text,
          },
        ),
        "chat/room/" + "${widget.room.id}" + "/message",
      );
      if (response.statusCode == 200) {
        _messageController.text = "";
        _get();
      }
    } catch (err) {
      showSnackbar(context, '${err.toString()}');
    }
  }

  Future _get() async {
    Api api = new Api();
    try {
      var response =
          await api.get("chat/room/" + "${widget.room.id}" + "/messages");
      if (response.statusCode == 200) {
        var jsonData = jsonDecode(response.body);
        var messageList =
            (jsonData as List).map((e) => Message.fromJson(e)).toList();
        messages = messageList;
        return messages;
      }
      return [];
    } catch (err) {
      showSnackbar(context, '${err.toString()}');
    }
  }
  Future<void> _initPusher() async {
    Store store = new Store();
    String token = await store.read('token');
    try {
      pusher = PusherClient(
        pusherKey,
        PusherOptions(
          host: broadcastPath,
          encrypted: false,
          auth: PusherAuth(
            broadcastPath + "/broadcasting/auth",
            headers: {
              'Content-Type': 'application/json',
              'Authorization': 'Bearer $token'
            },
          ),
          cluster: 'eu',
        ),
        enableLogging: true,
      );
      channel = pusher?.subscribe("private-chat." + widget.room.id.toString());

      pusher?.onConnectionStateChange((state) {
        print(
            "previousState: ${state?.previousState}, currentState: ${state?.currentState}");
      });

      pusher?.onConnectionError((error) {
        print("error: ${error?.message}");
      });

      channel?.bind('chat-event', (event) {
        setState(() {});
      });
    } catch (e) {
      print(e.toString());
    }
  }
}

But the moment I comment out the above file and pusher_client: ^2.0.0 in pubspec.yaml and then run flutter run my application gets run on ios simulator.

Can anyone help please

this is a link to github with more details https://github.com/chinloyal/pusher_client/issues/46

Zia
  • 506
  • 3
  • 20

1 Answers1

3
  1. First of all, update your ios/Podfile to contain the following line:

    platform :ios, '13.0'

  2. Add the following code to your post_install command within the Podfile:

    target.build_configurations.each do |config|
             config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
         end
    
  3. For example, my post_install looks like this:

    post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' end end end

  4. Go to your pubspec.yaml. And replace the pusher_client dependency with my fork:

    pusher_client: git: url: git://github.com/thijskuilman/pusher_client.git

    Go to your project root folder. Run flutter clean && flutter pub get && cd ios && pod install

  5. Try to run the app on your iOS device or simulator

Мikle
  • 31
  • 1
  • this worked for me 100%. (m1pro) – Мikle Feb 08 '22 at 20:40
  • Don't you have solution with pusher_client itself? – Zia Feb 09 '22 at 05:33
  • follow these steps and it will work. The problem lies in "/Users/zia/Desktop/projects/com_tingsapp_mover/ios/Pods/Sodium/Sodium/libsodium/libsodium-ios.a(libsodium_la-ae ad_xchacha20poly1305.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64". Next, you need to build the application on a real device in debug mode (I don’t know how it works), after which the builds on the IOS simulator will also work (if there are connection problems). It works well in my project – Мikle Feb 10 '22 at 17:33
  • Dear Mikle, it is working thanks for this solution. can you explain what is the difference of using a package from github and installing that package from pub.dev? is this save to use github packages which are not verified by pub.dev? and what changes you made on pusher_client package? – Zia Feb 14 '22 at 05:14
  • this works like a magic !! thank u man – Moataz Fouuad Mar 14 '22 at 18:01