Welcome to the Apple Developer Forums

Post your questions, exchange knowledge, and connect with fellow developers and Apple engineers on a variety of software development topics.

For questions about using Apple hardware and services, visit Apple Support Communities

Posts

Sort by:
Post not yet marked as solved
0 Replies
5 Views
Our product creates signed mobileconfig Profiles which install root certificates on MacOS devices (via a "com.apple.security.root" payload). For MacOS versions prior to Ventura the resulting certificates on the end user MacOS device's were marked as "Always Trust" for SSL in the trust details seen in Keychain Access. On MacOS Ventura the same setting for SSL for the CA certificate is shown as "no value specified" in the trust details of Keychain Access. The "no value specified" seems to result in web servers presenting certs chained to the CA not being trusted, at least in Safari. Is there any Profile based option to specify the provided CA certificate should be trusted (equivalent of "Always Trust") for SSL on Ventura? STEPS TO REPRODUCE: 1) Via a mobileconfig based Profile, install a CA certificate via a "com.apple.security.root" payload  2) Visit the resulting certificate entry in Keychain Access 3) Expand the "Trust" section/settings of the certificate 4a) Prior to MacOS Ventura all of the items such as "Secure Socket Layer (SSL)", "Secure Mail", etc were all marked as "Always Trust". 4b) In Ventura "Secure Socket Layer (SSL)" is marked as "no value specified" while all the other items are marked as "Always Trust"
Posted
by
Post not yet marked as solved
1 Replies
13 Views
Hello, I recently was rejected for the following reason: However, your app does not comply with: Legal 5.1.1 We noticed that your app requires users to register with personal information to access the app’s content and purchase in-app purchase products that are not account based. Apps cannot require user registration prior to allowing access to app content and features that are not associated specifically to the user. User registration that requires the sharing of personal information must be optional or tied to account-specific functionality. To resolve this issue, please revise your app to not require users to register before purchasing in-app purchase products that are not account based. You may explain to the user that registering will enable them to access the purchased content from any of their iOS devices and provide them a way to register at any time, if they wish to later extend access to additional devices. Resources See guideline 5.1.1(v) - Account Sign-In to learn more about our requirements for apps with account-based content and features. I replied: We require the user to login/sign up because it relates directly to the core functionality of our App. If the user deletes the App and chooses to reinstall it, his data will be saved on our server because the sign up system allows their data to be saved. This allows the User to restore all his in-app purchases and for our database to always keep track of the User’ in-app purchased consumable items. Apple requires a restore feature for in app purchases and we allow the user to restore his in app purchases by tying their account to an email or social media login. The login is required to prevent users from hacking the app. The diamond and coin systems are stored on our back end database servers. Once a user logins in, the back end stores how much coins and diamonds are associated with that account. This prevents users from manually altering how many coins or diamonds they have. It preserves the integrity of the app and the Apple App Store itself. Our servers store all user progression and data. Without the login / sign up system, we cannot sync the back end database. The login / sign up feature is crucial to the functionality of the app to prevent hacking and to keep track of the users database and more importantly, keep account and restore capabilities available for any in app purchases. To which the review board responded with: Although requesting that users register to for tracking users’ purchases and game progresses is acceptable, requiring users to fully register for an account before entering the game is not. Users should be allowed to access none account-based features before registration and login. You may also choose to alert users that accessing game without binding an account may result in losing game progress or in-app purchase items. To resolve this issue, please revise your app to let users freely access your app’s non account-based features, such as accessing the game, prior to registration or login. Once the user decides to use account-based features, the app may present the registration or login feature at that time. My understanding is this... I need to implement a "play as guest" mode where Users do not need to register. This will automatically generate an account for that User. However, am I allowed to require the user to register before conducting any in-app purchases, or other activities on the app?? What is this asking for? Do I need to allow the guest user to be able to purchase and do all the things a registered user can?
Posted
by
Post not yet marked as solved
0 Replies
10 Views
Intro When training RNN models on time-series datasets (batch_size, timestamps, features) with variable-length timestamps, the official TF documentation suggests padding the examples (so all the examples have the same number of timestamps) and then use the Masking layer before the RNN layers (SimpleRNN, LSTM, GRU) to avoid using the padded timestamps during both training and inference. Problem Even though the models implemented with LSTM and GRU layers ignore padded timestamps as defined in the Masking layer during training, it seems that they ignore the mask during inference (model.predict() or model.evaluate()). However, the SimpleRNN layer works as intended (ignores the padded values during both training and inference). Below are the versions of my TF packages: tensorflow-deps=2.10.0 tensorflow-estimator=2.9.0 tensorflow-macos=2.9.0 tensorflow-metal=0.5.0 Code The code below trains a very simple LSTM network on some random data which are padded, and then I use the model to predict on two examples which should result in the same prediction probabilities if the layers work as intended, but I get different results indicating the masking layer doesn't work during inference. However, the code works as intended in Colab. import tensorflow as tf from tensorflow import keras import numpy as np import random as python_random #Make the values reproducible np.random.seed(1375) python_random.seed(1375) tf.random.set_seed(1375) #The padding value padding_value = 2.0 #Number of samples and features in the dataset num_samples = 1000 num_features = 3 #Create a dataset with variable-length timestamps data = [np.random.randn(np.random.randint(1,10),num_features) for _ in range(num_samples)] #Create random binary target values target = np.random.randint(0,2, num_samples) #Pad the dataset with the padding value so all the examples have the same number of timestamps data = keras.preprocessing.sequence.pad_sequences(data, dtype="float32", padding="post", value = padding_value) #Defining and training the model input = keras.layers.Input(shape=(None, data.shape[2])) x = keras.layers.Masking(mask_value = padding_value)(input) x = keras.layers.LSTM(6)(x) output = keras.layers.Dense(1, activation="sigmoid")(x) model = keras.Model(input, output) model.compile( loss= "binary_crossentropy", metrics = ["accuracy"], optimizer = "RMSprop" ) history = model.fit(x = data, y= target, validation_split=0.2, batch_size=100, epochs=10) ############## ##Below I am creating two samples (all_ones_no_pad, all_ones_with_pad), ##But I am padding the second one with a lot of padding. ##If the padded values are ignored during inference (which is what is intended), they must result ##in the same prediction probabilities. ############## all_ones_no_pad = np.ones(shape=(1, 8, num_features)) all_ones_with_pad = np.ones(shape=(1, 150, num_features)) all_ones_with_pad[:,8:,:] = padding_value no_padded_prediction = model.predict(all_ones_no_pad) padded_prediction = model.predict(all_ones_with_pad) if no_padded_prediction == padded_prediction: print(f"Both examples result in the same prediction prob {padded_prediction} as intended.") else: print(f"Examples were treated differently. Prediction probs are {no_padded_prediction} and {padded_prediction}") The code finishes running, but I get the following error in the console: 2023-02-02 12:29:56.458998: W tensorflow/core/common_runtime/forward_type_inference.cc:231] Type inference failed. This indicates an invalid graph that escaped type checking. Error message: INVALID_ARGUMENT: expected compatible input types, but input 1: type_id: TFT_OPTIONAL args { type_id: TFT_PRODUCT args { type_id: TFT_TENSOR args { type_id: TFT_LEGACY_VARIANT } } } is neither a subtype nor a supertype of the combined inputs preceding it: type_id: TFT_OPTIONAL args { type_id: TFT_PRODUCT args { type_id: TFT_TENSOR args { type_id: TFT_FLOAT } } } while inferring type of node 'cond_19/output/_23' 2023-02-02 12:29:56.461511: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:113] Plugin optimizer for device_type GPU is enabled.
Posted
by
Post not yet marked as solved
0 Replies
17 Views
I have an app which uses URLSession-based networking and URLCache for storing network requests on disk. I noticed that when the storage size of URLCache reaches the diskCapacity, the eviction strategy seems to be to remove all entries, which is a problem in my use case. So I decided to write an URLCache subclass which would provide a custom storage for cached responses and which would implement LRU eviction strategy with better control. As URLCache's documentation states, subclassing for this purpose should be supported: The URLCache class is meant to be used as-is, but you can subclass it when you have specific needs. For example, you might want to screen which responses are cached, or reimplement the storage mechanism for security or other reasons. However, I ran into problems with trying to use this new URLCache subclass with URLSession networking. I have a test resource which I fetch using HTTP GET. The response headers contain: Cache-Control: public, max-age=30 Etag: <some-value> When using the standard, non-subclassed URLCache, the first request loads the data from network as expected (verified with HTTP proxy). The second request doesn't go to the network, if done within first 30 seconds, as expected. Subsequent requests after 30 seconds cause conditional GETs with Etag, as expected. When using a URLCache subclass, all requests load the data from network - max-age doesn't seem to matter, and no conditional GETs are made. It seems that the URLCache does something special to the CachedURLResponse instances after they're loaded from its internal storage, and this something affects how URLSession handles the HTTP caching logic. What am I missing here? I've written a very minimal URLCache implementation to demonstrate this problem. This class stores and loads CachedURLResponse instances using NSKeyedArchiver / NSKeyedUnarchiver, and it supports only zero or one response. Note that there are no calls to super - this is by design, since I want to use my own storage. Here's the implementation: class CustomURLCache: URLCache { let cachedResponseFileURL = URL(filePath: NSTemporaryDirectory().appending("entry.data")) // MARK: Internal storage func read() -> CachedURLResponse? { guard let data = try? Data(contentsOf: cachedResponseFileURL) else { return nil } return try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as! CachedURLResponse } func store(_ cachedResponse: CachedURLResponse) { try! (try! NSKeyedArchiver.archivedData(withRootObject: cachedResponse, requiringSecureCoding: false)).write(to: cachedResponseFileURL) } // MARK: URLCache Overrides override func cachedResponse(for request: URLRequest) -> CachedURLResponse? { read() } override func getCachedResponse(for dataTask: URLSessionDataTask, completionHandler: @escaping (CachedURLResponse?) -> Void) { guard let response = read() else { completionHandler(nil) return } completionHandler(response) } override func storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest) { store(cachedResponse) } override func storeCachedResponse(_ cachedResponse: CachedURLResponse, for dataTask: URLSessionDataTask) { store(cachedResponse) } } My test case: func test() { let useEvictingCache = false let config = URLSessionConfiguration.default if useEvictingCache { config.urlCache = CustomURLCache() } else { config.urlCache = URLCache(memoryCapacity: 0, diskCapacity: 1024 * 1024 * 100) } self.urlSession = URLSession(configuration: config) let url = URL(string: "https://example.com/my-test-resource")! self.urlSession?.dataTask(with: URLRequest(url: url), completionHandler: { data, response, error in if let data { print("GOT DATA with \(data.count) bytes") } else if let error { print("GOT ERROR \(error)") } }).resume() }
Posted
by
Post not yet marked as solved
0 Replies
13 Views
VoIP call works perfectly fine at start until i grant access to WKWebView media(microphone access). I am using WKWebView to highlight the spoken word using web speech engine. If i use webView i can't hear VoIP call audio and if i stop webView VoIP call works perfectly fine. What i want to achieve is to stay in VoIP call as well as work with webView to highlight the spoken words and I want to know if there is any problem in giving microphone access to VoIP as well as WKWebView simultaneously. Please post your question if i am not clear about anything or you want to know more information.
Posted
by
Post not yet marked as solved
0 Replies
14 Views
Wondering if anyone can help me figure out what could cause this crash? It seems to happen only on one of my coworkers iPhone 13 running iOS 16.2 my phone is a iPhone 11 Max Running iOS 16.1 and this crash is not happening. #0 (null) in UIKitNavigationBridge.containingNavControllerFromLastAttemptedPop.getter () #1 (null) in UIKitNavigationBridge.containingNavControllerFromLastAttemptedPop.getter () #2 (null) in UIKitNavigationBridge.isInTransientPop.getter () #3 (null) in UIHostingController.resolveRequiredBridges(in:allowedActions:) () #4 (null) in UIHostingController.didMove(toParent:) () #5 (null) in @objc UIHostingController.didMove(toParent:) () #6 (null) in -[UIViewController removeChildViewController:notifyDidMove:] () #7 (null) in -[UINavigationController removeChildViewController:notifyDidMove:] () #8 (null) in -[UIViewController dealloc] () #9 (null) in -[UINavigationController viewDidDisappear:] () #10 (null) in -[UIViewController _setViewAppearState:isAnimating:] () #11 (null) in __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke_2 () #12 (null) in __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke () #13 (null) in __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ () #14 (null) in -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] () #15 (null) in -[UIViewController _setViewAppearState:isAnimating:] () #16 (null) in -[UIViewController __viewDidDisappear:] () #17 (null) in -[UIViewController _endAppearanceTransition:] () #18 (null) in __97-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:]_block_invoke_3 () #19 (null) in -[UIViewController _executeAfterAppearanceBlock] () #20 (null) in -[_UIAfterCACommitBlock run] () #21 (null) in -[_UIAfterCACommitQueue flush] () #22 (null) in _runAfterCACommitDeferredBlocks () #23 (null) in _cleanUpAfterCAFlushAndRunDeferredBlocks () #24 (null) in _UIApplicationFlushCATransaction () #25 (null) in _UIUpdateSequenceRun () #26 (null) in schedulerStepScheduledMainSection () #27 (null) in runloopSourceCallback () #28 (null) in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ () #29 (null) in __CFRunLoopDoSource0 () #30 (null) in __CFRunLoopDoSources0 () #31 (null) in __CFRunLoopRun () #32 (null) in CFRunLoopRunSpecific () #33 (null) in GSEventRunModal () #34 (null) in -[UIApplication _run] () #35 (null) in UIApplicationMain () #36 (null) in closure #1 in KitRendererCommdowon(_:) () #37 (null) in runApp<A>(_:) () #38 (null) in static App.main() () #39 0x0000000100466550 in static AppRoot.$main() at AppRoot.swift:13 #40 (null) in main () #41 (null) in start ()
Posted
by
Post not yet marked as solved
0 Replies
10 Views
Hello Dears, We're trying to setup apple pay button on our website with a payment gateway We're in the token step Creating an Apple Pay payment token is the first step to creating a Tap(Payment gateway token) when we're sending the certificate to the apple endpoint we should send it as a PEM file, not CER The error that we got "message": "unable to set private key file: '/Users/a/Documents/Sites/ish/storage/apple-pay/tap-payment/apple-pay.pem' type PEM", since we contact the payment gateway the advised us to contact apple support.. can you help us please. Thanks for understanding
Posted
by
Post not yet marked as solved
0 Replies
9 Views
Hello, I'd like to provide Wallet Order Tracking to my customers but I'm unable to add the order by clicking a link. It downloads the file instead of directly saving it in Wallet like for Coupon or Cards do. Is this auto opening feature only for .pkpass files or should it work on .order files too ? Thanks, Guillaume
Posted
by
Post not yet marked as solved
0 Replies
17 Views
Hi, My application requires users to register and enter a postal address to operate. From this postal address, registered users can see the ads around them within a 30km radius, and only these ads. I've had the same app validated 12 times with the same functionality on the AppStore, but today I'm asked to open the app to allow free access to the app's non-account based features. This is simply impossible since it is a proximity social network. It was never intended to open the application without registering first. How to solve this? Thanks Regards
Posted
by
Post not yet marked as solved
1 Replies
25 Views
Hi all, I’m trying to build a simple Apple Watch App and move on from there. When I connect my iPhone to my Mac via USB and start Xcode, Xcode recognises my iPhone and Apple Watch. In “Window > Devices and Simulators” (shift-cmd-2) it shows my iPhone and paired Apple Watch.  So far, so good. I switched my iPhone to ‘Developer Mode’ (Settings > Privacy > Developer Mode) and did the same on my Apple Watch. The (standard ‘Hello world’) App will not run on my Apple Watch because of the “waiting for first unlock” message (see: https://developer.apple.com/forums/thread/716113) . Maybe this has something to do with 'Developer Mode'. I noticed that the Developer switch on my Apple Watch is always in the “Off” position. When I switch it on, the Apple Watch reboots and aks me if I want to enter ‘Developer Mode’. Then I have to ‘trust the computer’ and the switch is in the Off position again. So I unpaired my apple watch from my iPhone and repaired (and reinstalled) my Apple Watch. When I look in "Settings > Privacy" on my Apple Watch there is no ‘Developer Mode’ switch anymore. The last item in the list is ‘Focus’ and then the ‘Report’ option.  The Apple Watch and iPhone both have Bluetooth enabled, both have Handoff enabled and are on the same WiFi network. Rebooted the iPhone and Apple Watch several times. Anybody know how I can have the ‘Developer Mode’ option (switch) return on my Apple Watch? iPhone XR, iOS 16.3 / Apple Watch Ultra, WatchOS 9.3 / Xcode 14.2 Thanks in advance!
Posted
by
Post not yet marked as solved
1 Replies
19 Views
When I set up a dragGesture using a gestureState, the gestureState has the correct value during the onChange phase. But when the onEnded phase is entered, the gesturePhase is reset to its original default value. Is this the correct behavior? I would like the gestureState to retain its value since I want to make use of it in the onEnded phase. After the onEnded phase is completed, then the gestureState should be reset to its original value.
Posted
by
Post not yet marked as solved
0 Replies
14 Views
Hello all, It's been over a month since we at EdSofta got a DUNS number and applied to be enrolled for an Apple developer account. We've not gotten a response yet. We've also sent their support messages and no response too. Who can kindly advise next steps? Thanks, Enoch
Posted
by
Post not yet marked as solved
0 Replies
14 Views
iOS application summary: (1) Single full-screen showing card from array of cards (2) 2 buttons: Next and Prior -- to advance forward and backward through array of cards (3) Picker control that allows for new set of cards where different picker selection options trigger differ subsets of full card array. .pickerStyle(.menu) is being used Voice Control works fine when app starts -- "Tap Next" and "Tap Prior" move the displayed card from the array forward and backward Problem when new picker selection is made with .pickerStyle(.menu): (1) First card from new array shows correctly (2) Voice Control (e.g. "Tap Next") does not function until screen is physically touched (does not matter where screen is touched) (3) Voice Control works just fine when .pickerStyle is changed from .menu to either .inline or .wheel Picker code: Picker("Cards", selection: $selectedCards) { Text("All Cards").tag(Strings.all) Text("2345 Cards").tag(Cards.twoThruFive) Text("1st Cards").tag(Cards.one) Text("2nd Cards").tag(Cards.two) Text("3rd Cards").tag(Cards.three) Text("4th Cards").tag(Cards.four) Text("5th Cards").tag(Cards.five) Text("6th Cards").tag(Cards.six) } .pickerStyle(.menu) .onChange(of: selectedCards) { tag in switch tag { case .all: cardsViewModel.newAllStrings() case .twoThruFive: cardsViewModel.new2345Cards() case .one: cardsViewModel.newOneCards() case .two: cardsViewModel.newTwoCards() case .three: cardsViewModel.newThreeCards() case .four: cardsViewModel.newFourCards() case .five: cardsViewModel.newFiveCards() case .six: cardsViewModel.newSixCards() } }
Posted
by
Post not yet marked as solved
0 Replies
13 Views
I am trying to reactivate my membership in order to reactivate my apps, despite paying for my membership 3 weeks ago and it said it renewed. When I go to my apps I see they are Pending Agreement. So I go to the agreements section and it says i need to renew. It takes me to my account, but it does not show the company any more in the dropdown in the top right. It only has me. I see an option to enroll as a developer so I click on enroll and it says i can't enroll as I'm already an account holder. But no way to activate that membership. Can someone please help and guide us as we have 40+ apps that are no longer available in the App Store. We can't reactivate due to Apple's flow being broken. What am i missing or how do we reactivate the account ASAP? I've called 6 Apple phone numbers but they can't help with dev support. I submitted a contact us and it said they would get back in 1 to 2 business days. Unfortunately that's too big of an impact to my business, my team, my clients and their members if it's going to take this long. Please provide guidance on how to resolve. And Apple please fix your bugs. Thx.
Posted
by
Post not yet marked as solved
0 Replies
16 Views
Hello everyone, Apple CarPlay is implemented in one of my applications by using MediaPlayer Framework. It is working properly if iPhone is locked, the App is in the background, or in an Active state. But I want to play audio from CarPlay even if the App is in a terminated state similar to Spotify app does. In case of application is not opened in the phone, on CarPlay display selecting the station does not play the song. You can see in the below videos for both cases: [https://algoworks-my.sharepoint.com/:v:/p/ankit_singh/EQ3HzSKEl-pGpMIK0vh7HIkBtWg50-vco3aTyxOZevmuTA?e=2pmmWB) [https://algoworks-my.sharepoint.com/:v:/p/ankit_singh/EeI8qai1iftKvwo9nogCJREBFQXCf3qf8d-qwIt-25CB7g?e=bkYqAH) I tried many things but not able to achieve this. So help me with this and share some code to review. Thanks.
Posted
by
Post not yet marked as solved
0 Replies
17 Views
I'm trying to build an XCFramework for our use of WebRTC and am using an Apple Silicon Mac (Mac Studio). I've downloaded the WebRTC stuff from Google and installed all their tools and used their tools to generate an Xcode project version. I can run Xcode and build a framework library. I've set the "arch" in Xcode to be the $ARCHS_STANDARD plus x86_64 (for simulator use by our developers still using Intel based Macs) Using the documentation at https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle I create an archive for iOS and one for iOS Simulator % xcodebuild archive -project all.xcodeproj -scheme framework_objc_signed_bundle -destination "generic/platform=iOS" -archivePath "archives/WebRTC" % xcodebuild archive -project all.xcodeproj -scheme framework_objc_signed_bundle -destination "generic/platform=iOS Simulator" -archivePath "archives/WebRTC_simulator" ONLY_ACTIVE_ARCH=NO SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES First issue is it doesn't seem to create an X86 version for simulator based on running "% lipo -archs" on the actual binary library in the WebRT_simulator.framework, which only shows "arm64", though I don't know if that is valid. Then when I try and create the XCFramework using % xcodebuild -create-xcframework -archive archives/WebRTC.xcarchive -framework WebRTC.framework -archive archives/WebRTC_simulator.xcarchive -framework WebRTC.framework -output WebRTC.xcframework I end up with this: A library with the identifier 'ios-arm64' already exists. I found a post asking about this result but unfortunately it linked to another post for an answer and that post no longer exists. What am I doing wrong and how can I go about creating the WebRTC XCFramework that runs on device, and both architectures simulators? Following the Apple docs ends up with an error that I don't understand.
Posted
by
Post not yet marked as solved
0 Replies
14 Views
My ipad pro gen3 11' has been randomly turned off and rebooted. I found log : "bug_type":"142" in backboardd.wakeups_resource.ips Community said the bug causes randomly reboot. Why is the issue coming up and how is the problem solved?
Posted
by
Post not yet marked as solved
0 Replies
19 Views
Currently am working on Objective C project and for some dependency reason this project cant migrate to latest Swift/Xcode. This project only runs/build on Xcode 10 with legacy build system. My current MacOS version is 11.6.8 MacOS Big Sur. If I update my Mac OS to 11.7.3 or later versions then will Xcode 10 work? When I try to install fresh Xcode 10 in another Mac having updated Mac OS i.e. version 12/13 then I was getting error related to compatibility. And its is not possible to freshly install Xcode 10 in latest MacOS. So my question is will my project runs/build or Xcode 10 is compatible if I update current macOS from 11.6.8 to 11.7.3 or later versions?
Posted
by
Post not yet marked as solved
0 Replies
15 Views
I am listening for the ES_EVENT_TYPE_AUTH_MMAP event, but did not see mmap MAP_SHARED authentication callback, only see the following logs 2023-02-02 20:11:32.713347+0800 0x12ac8 Default 0x0 404 0 com.test.es: ➔D|320 [M_IPC]: ES_EVENT_TYPE_AUTH_MMAP: pid:1443, path:/Users/armmini/go/src/myapp/maptest, sourcePath:/Users/armmini/go/src/myapp/maptest, path_tuncated:0, flag:0x40002, protection:0x1, max_protection:0x7 2023-02-02 20:11:32.715234+0800 0x12ac8 Default 0x0 404 0 com.test.es: ➔D|320 [M_IPC]: ES_EVENT_TYPE_AUTH_MMAP: pid:1443, path:/Users/armmini/go/src/myapp/maptest, sourcePath:/Users/armmini/go/src/myapp/maptest, path_tuncated:0, flag:0x12, protection:0x3, max_protection:0x3 2023-02-02 20:11:32.715402+0800 0x12ac8 Default 0x0 404 0 com.test.es: ➔D|320 [M_IPC]: ES_EVENT_TYPE_AUTH_MMAP: pid:1443, path:/Users/armmini/go/src/myapp/maptest, sourcePath:/Users/armmini/go/src/myapp/maptest, path_tuncated:0, flag:0x12, protection:0x3, max_protection:0x3 Demo as follows package main /* #include <sys/mman.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/shm.h> #include <sys/ipc.h> #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) int my_shm_new(char *name) { shm_unlink(name); return shm_open(name, O_RDWR|O_CREAT|O_EXCL, FILE_MODE); } int my_shm_open(char *name) { return shm_open(name, O_RDWR); } */ import "C" import ( "flag" "fmt" "unsafe" ) const SHM_Name = "my_shm" const SHM_Size = 1000 * 1000 type SHM_Data struct { data [1024]byte } func main() { send(*msg) // receive() } func send(msg string) { fd, err := C.my_shm_new(C.CString(SHM_Name)) if err != nil { fmt.Printf("1 %v", err) return } C.ftruncate(fd, SHM_Size) ptr, err := C.mmap(nil, SHM_Size, C.PROT_READ|C.PROT_WRITE, C.MAP_SHARED, fd, 0) if err != nil { fmt.Printf("2 %v", err) return } C.close(fd) data := (*SHM_Data)(unsafe.Pointer(ptr)) msgByte := []byte(msg) for idx, b := range msgByte { data.data[idx] = b } } func receive() { fd, err := C.my_shm_open(C.CString(SHM_Name)) if err != nil { fmt.Println(err) return } ptr, err := C.mmap(nil, SHM_Size, C.PROT_READ|C.PROT_WRITE, C.MAP_SHARED, fd, 0) if err != nil { fmt.Println(err) return } C.close(fd) data := (*SHM_Data)(unsafe.Pointer(ptr)) bt := make([]byte, 0) for _, b := range data.data { bt = append(bt, b) } fmt.Println("Receive:", string(bt)) }
Posted
by

Pinned Posts

Categories

See all