我刚刚从Xcode 7更新到8 GM并且在Swift 3兼容性问题中我注意到我的设备令牌已停止工作.他们现在只读'32BYTES'.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
print(deviceToken) // Prints '32BYTES'
print(String(data: deviceToken , encoding: .utf8)) // Prints nil
}
Run Code Online (Sandbox Code Playgroud)
在更新之前,我能够简单地将NSData发送到我的服务器,但现在我很难解析令牌.
我在这里错过了什么?
编辑:我只是测试转换回NSData,我看到了预期的结果.所以现在我只是对新数据类型感到困惑.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
print(deviceToken) // Prints '32BYTES'
print(String(data: deviceToken , encoding: .utf8)) // Prints nil
let d = NSData(data: deviceToken)
print(d) // Prints my device token
}
Run Code Online (Sandbox Code Playgroud) 所以我的朋友从OneSignal收到了这封电子邮件
由于即将到来的iOS 13版本可能会发生更改,因此在使用Xcode 11构建应用程序之前,必须先更新到最新版本的iOSSDK。OneSignal的所有包装SDK(包括React Native,Unity和Flutter)都已经过也更新了。原因是与iOS 13一起发布的Xcode 11打破了OneSignal之类的应用程序和库用于获取设备推送令牌的通用技术。如果您不使用我们的新SDK,那么新用户将无法从您的应用订阅通知。
我对此感到好奇。
这是我们在iOS 12上获取设备通知令牌的方式
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
var token = ""
for i in 0..<deviceToken.count {
token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
}
print("Notification token = \(token)")
}
Run Code Online (Sandbox Code Playgroud)
在iOS 13上获取它的正确方法是什么?我应该为当前开发的应用程序采用新方法还是旧方法仍然可行?
Google Auth Util允许Android开发人员验证其服务器收到的请求来自Android设备.
设备会根据与设备关联的Google帐户从Google获取令牌,然后设备的请求会随该令牌一起发送到服务器,然后服务器会询问Google是否有效.任何密钥都不在应用程序源之外,因此恶意人员无法破解应用程序并访问私钥和软件请求到服务器.
我已经看了一段时间,似乎Apple没有提供这样的东西,但我希望有一些功能相似的功能,我可以用于iOS.
如何将推送通知发送到在开发配置文件下运行的构建?
谁能帮帮我吗?
iphone objective-c apple-push-notifications ios provisioning-profile
我正在处理推送通知.我编写了以下代码来获取设备令牌.
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"This is device token%@", deviceToken);
}
-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error %@",err);
}
Run Code Online (Sandbox Code Playgroud) 我们的RegisteredForRemoteNotifications代码中断,因为使用以下方法检索了令牌:
deviceToken.ToString().Trim('<').Trim('>').Replace(" ", "");
Run Code Online (Sandbox Code Playgroud)
这曾经可以使用,但不适用于iOS 13,因为数据如下所示:
"{length = 32, bytes = 0x965b251c 6cb1926d e3cb366f dfb16ddd ... 5f857679 376eab7c }"
Run Code Online (Sandbox Code Playgroud)
对于如何使用目标c和swift正确执行此操作,有答案,但是我还没有找到使用C#的答案。
参考:
https://nshipster.com/apns-device-tokens/
如何用Xamarin做到这一点?
ios ×5
objective-c ×2
swift ×2
android ×1
c# ×1
cocoa-touch ×1
devicetoken ×1
ios13 ×1
iphone ×1
swift3 ×1
xamarin ×1
xamarin.ios ×1
xcode11 ×1