[英]iOS- Push notification issue
目前,我的一名PHP開發人員為我提供了適用於iOS設備的推送通知API
問題是:如果我在任何瀏覽器(Chrome / Safari / Firefox等)中使用各自的參數運行該api,則會在iOS設備的前台收到通知。 但不是iOS應用程序(Xcode)本身
在我的應用中,我使用了如下代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register for Push Notitications, if running on iOS 8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
#pragma mark
#pragma mark -- Push Notification Delegate Methods
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings: (UIUserNotificationSettings *)notificationSettings{
//register to receive notifications
[application registerForRemoteNotifications];
}
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
// Prepare the Device Token for Registration (remove spaces and < >)
devToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"My token is: %@", devToken);
// My token is: cd2887c4093569b3eed142320f21a81e521e486cf5c40467390901d3a191398b
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:deviceToken forKey:@"deviceToken"];
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{
NSLog(@"Failed to get token, error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"%s..userInfo=%@",__FUNCTION__,userInfo);
}
我得到回應:(在didReceiveRemoteNotification中)
{
aps = {
alert = "You're login successfully";
sound = default;
};
}
此消息未顯示在狀態欄(屏幕頂部)上。 iOS端(或PHP端)是否有任何問題
如果問題出在iOS方面->我該怎么做
這是我的測試推送通知API:
您能幫我解決這個問題嗎
您需要自定義視圖,以便在應用程序位於前景中時顯示“推送通知橫幅”。 您可以使用JCNotificationBannerPresenter
。 使用以下鏈接遵循示例代碼。
https://github.com/jcoleman/JCNotificationBannerPresenter
#import "JCNotificationCenter.h"
#import "JCNotificationBannerPresenterSmokeStyle.h"
- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)notification {
NSString* title = @"Push Notification";
NSDictionary* aps = [notification objectForKey:@"aps"];
NSString* alert = [aps objectForKey:@"alert"];
[JCNotificationCenter
enqueueNotificationWithTitle:title
message:alert
tapHandler:^{
NSLog(@"Received tap on notification banner!");
}];
}
希望對您有幫助。
沒問題,這是默認行為。
當您位於應用程序內部時,在主屏幕上時顯示在屏幕頂部的橫幅不會出現。
您需要在didReceiveRemoteNotification
內讓應用程序自己對通知進行操作。 這可能會顯示警報,在標簽欄上添加徽章等,但橫幅廣告僅在您不在應用程序外部時顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.