unity專案IOS本地推送訊息

2022-09-08 20:54:18 字數 1903 閱讀 5425

unity專案ios客戶端實現本地訊息推送,需求遊戲在後台執行的時候,推送獎勵已滿。

實現。1.註冊通知:

- (void)registerapn 

}];} else

}

2.檢查許可權

- (void)checkusernotificationenable

}else );

}}];

}else );

}else

}}

3.新增通知

在需要使用的地方呼叫這個函式,獎勵滿足時候,通過lua呼叫這個函式

- (void)addlocalnoticewithid:(nsstring *)noticeid title:(nsstring*)title context:(nsstring*)context time:(int)time

nsstring *identifier = noticeid;

nstimeinterval time = [[nsdate datewithtimeintervalsincenow:sectime] timeintervalsincenow];

untimeintervalnotificationtrigger *trigger = [untimeintervalnotificationtrigger triggerwithtimeinterval:time repeats:no];

unnotificationrequest *request = [unnotificationrequest requestwithidentifier:identifier content:content trigger:trigger];

[center addnotificationrequest:request withcompletionhandler:^(nserror *_nullable error) ];

}

4.移除通知

// 移除某乙個指定的通知

- (void)removeonenotificationwithid:(nsstring *)noticeid

nslog(@"移除currentid:%@",noticeid);

}];[center removependingnotificationrequestswithidentifiers:@[noticeid]];

}else }}

}// 移除所有通知

- (void)removeallnotification else

}

5.跳轉到設定介面

dispatch_async(dispatch_get_main_queue(), ^

}else

}});

}

#pragma mark - ios10-unusernotificationcenterdelegate

// 彈出通知

- (void)usernotificationcenter:(unusernotificationcenter *)center willpresentnotification:(unnotification *)notification withcompletionhandler:(void (^)(unnotificationpresentationoptions))completionhandler

- (void)usernotificationcenter:(unusernotificationcenter *)center didreceivenotificationresponse:(unnotificationresponse *)response withcompletionhandler:(void (^)())completionhandler

差不多就是這些

參考:

ios本地推送

第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定10秒之後 nsdate pushdate nsdate datewithtimeintervalsin...

iOS 本地推送

通知完一定要取消,ios最多允許最近本地通知數量是64個,超過限制的本地通知將被忽略。第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定10秒之後 nsd...

iOS本地推送

第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定10秒之後 nsdate pushdate nsdate datewithtimeintervalsin...